MaryCoding
MaryCoding

Reputation: 664

Jq tsv error in formatting an array/object

I have json file that I am able to loop and get the desired values with the below command. I am trying to gain some insights in displaying these values into a table format. I am using @tsv but getting an error object ({"release":...) cannot be tsv-formatted, only array. How can I get the below output display?

My desired output is shown below:

Release         Installed    Latest    Old      Deprecated
-------         ---------    ------    ---      ----------
test-app        1.0.0        2.0.0     true     false    

jq:

cat test.json | jq '.test[] | select((.outdated or .deprecated) and ((.release|startswith("update")) | not) and ((.release|startswith("upgrade")) | not))'

json:

{
    "test": [{
        "release": "myapp1",
        "Installed": {
            "version": "0.3.0",
            "appVersion": "v1.2.6"
        },
        "Latest": {
            "version": "",
            "appVersion": ""
        },
        "outdated": false,
        "deprecated": false
    }, {
        "release": "myapp2",
        "Installed": {
            "version": "6.5.13",
            "appVersion": "1.9.1"
        },
        "Latest": {
            "version": "",
            "appVersion": ""
        },
        "outdated": false,
        "deprecated": false
    }, {
        "release": "test-app",
        "Installed": {
            "version": "1.0.0",
            "appVersion": ""
        },
        "Latest": {
            "version": "2.0.0",
            "appVersion": ""
        },
        "outdated": true,
        "deprecated": false
    }, {
        "release": "update-app",
        "Installed": {
            "version": "1.0.0",
            "appVersion": ""
        },
        "Latest": {
            "version": "3.0.0",
            "appVersion": ""
        },
        "outdated": true,
        "deprecated": false
    }, {
        "release": "upgrade-app",
        "Installed": {
            "version": "2.0.0",
            "appVersion": ""
        },
        "Latest": {
            "version": "2.0.0",
            "appVersion": ""
        },
        "outdated": false,
        "deprecated": true
    }]
}

Upvotes: 0

Views: 562

Answers (1)

peak
peak

Reputation: 116870

Both @csv and @tsv expect an array as input, so you could just append the following to your jq filter:

| [.release, .Installed.version, .Latest.version, .outdated, .deprecated]
| @tsv

Upvotes: 3

Related Questions