Search code examples
escapingjqzshquoting

Broken JSON using JQ processing: Possible Bug?


I have a JSON I found that seems to fail to be able to remove an Array after indexing once. Here is the valid JSON below (according to jsonlint.com

Goal: Remove an outer array from what {was a valid JSON} on the outside.

Steps to reproduce

  1. validate JSON is valid
  2. run cat file.json | jq .rows
  3. Observe works OK
  4. try cat file.json | jq .rows[]

Observe my following error

zsh: no matches found: .rows[]

I also tried cat file.json | jq .rows | jq .[]

For good measure, here is the exact text that is failing but I think JQ should process like this according to JQ - How to define filter to remove brackets, quotes and commas from output array

{
"selfLink": null,
"id": "eyJwIjoiOGMxZjRkNjAtZDhmNS00YmU2LTg1YjMtYTA0NDExNDVkYmMwIiwicFYiOjE0fQ==",
"title": "My Daily Discovery",
"rows": [{
    "modules": [{
        "id": "eyJwIjoiOGMxZjRkNjAtZDhmNS00YmU2LTg1YjMtYTA0NDExNDVkYmMwIiwicFYiOjE0LCJtIjoiMTg3ZGVhMTMtNWI1ZS00OWYwLWI5YjktYjc5ODk3M2M2MjVmIiwibVYiOjEsIm1IIjoiYmMyMTQ4NDkifQ==",
        "type": "MIX_HEADER",
        "width": 100,
        "title": "",
        "description": "",
        "preTitle": "",
        "mix": {
            "id": "016574ac3abf29b2a6a1ae2c1b2f34",
            "title": "My Daily Discovery",
            "subTitle": "Songs by new and familiar artists inspired by your listening. Updates every morning.",
            "graphic": {
                "type": "SQUARES_GRID",
                "text": "My Daily Discovery",
                "images": [{
                    "id": "dummy-placeholder",
                    "vibrantColor": "#FFFFFF",
                    "type": "ARTIST"
                }]
            },
            "images": {
                "SMALL": {
                    "width": 320,
                    "height": 320,
                    "url": "https://images.tidal.com/0/EMACGMAC/CAEQCCIDMzI2KgcjRjlBMTkyMAQ?token=03c55020deef749a0a7608833cebe3ae2f8f33f6"
                },
                "MEDIUM": {
                    "width": 640,
                    "height": 640,
                    "url": "https://images.tidal.com/0/EIAFGIAF/CAEQCCIDMzI2KgcjRjlBMTkyMAQ?token=c391f21c624d0b58f4badc2185211b89eb2cee7f"
                },
                "LARGE": {
                    "width": 1500,
                    "height": 1500,
                    "url": "https://images.tidal.com/0/ENwLGNwL/CAEQCCIDMzI2KgcjRjlBMTkyMAQ?token=b055bb723e064256026fcb7d17a6dfa6ef839c25"
                }
            },
            "sharingImages": null,
            "mixType": "DISCOVERY_MIX",
            "mixNumber": null,
            "contentBehavior": "UNRESTRICTED",
            "shortSubtitle": null,
            "master": false,
            "titleColor": "#F9A192",
            "subTitleColor": "#F9A192",
            "detailImages": {
                "SMALL": {
                    "width": 320,
                    "height": 320,
                    "url": "https://images.tidal.com/0/EMACGMAC/CAEQCCIDMzI2KgcjRjlBMTkyMAQ4AQ?token=2d26406e237b5f9e830cac45b7ec6470ce71638f"
                },
                "MEDIUM": {
                    "width": 640,
                    "height": 640,
                    "url": "https://images.tidal.com/0/EIAFGIAF/CAEQCCIDMzI2KgcjRjlBMTkyMAQ4AQ?token=9406f1c8bc4061c7841f35156b0f81e9dc961d0b"
                },
                "LARGE": {
                    "width": 1500,
                    "height": 1500,
                    "url": "https://images.tidal.com/0/ENwLGNwL/CAEQCCIDMzI2KgcjRjlBMTkyMAQ4AQ?token=b8eb265be431640046cb1b376715d0ceaef19677"
                }
            }
        },
        "playbackControls": [{
            "shuffle": false,
            "playbackMode": "PLAY",
            "title": "Play",
            "icon": "play_tracks",
            "targetModuleId": "eyJwIjoiOGMxZjRkNjAtZDhmNS00YmU2LTg1YjMtYTA0NDExNDVkYmMwIiwicFYiOjE0LCJtIjoiNmU5OWY3ZjUtMDk4My00Mzk5LWFkYjEtZDk2NzRmMGQ2ZDQ5IiwibVYiOjEsIm1IIjoiNDgyMDRjMGMifQ=="
        }, {
            "shuffle": true,
            "playbackMode": "SHUFFLE",
            "title": "Shuffle",
            "icon": "shuffle_tracks",
            "targetModuleId": "eyJwIjoiOGMxZjRkNjAtZDhmNS00YmU2LTg1YjMtYTA0NDExNDVkYmMwIiwicFYiOjE0LCJtIjoiNmU5OWY3ZjUtMDk4My00Mzk5LWFkYjEtZDk2NzRmMGQ2ZDQ5IiwibVYiOjEsIm1IIjoiNDgyMDRjMGMifQ=="
        }]
    }]
}, {
    "modules": [{
        "id": "eyJwIjoiOGMxZjRkNjAtZDhmNS00YmU2LTg1YjMtYTA0NDExNDVkYmMwIiwicFYiOjE0LCJtIjoiNmU5OWY3ZjUtMDk4My00Mzk5LWFkYjEtZDk2NzRmMGQ2ZDQ5IiwibVYiOjEsIm1IIjoiNDgyMDRjMGMifQ==",
        "type": "TRACK_LIST",
        "width": 100,
        "title": "",
        "description": "",
        "preTitle": null,
        "showMore": null,
        "supportsPaging": false,
        "quickPlay": false,
        "listFormat": "COVERS",
        "scroll": "VERTICAL",
        "layout": "LIST",
        "pagedList": {
            "limit": 10,
            "offset": 0,
            "totalNumberOfItems": 10,
            "items": [{
                "id": 182220043,
                "title": "Hippies and Cowboys",
                "duration": 301,
                "version": null,
                "url": "https://tidal.com/browse/track/182220043",
                "artists": [{
                    "id": 6364193,
                    "name": "Cody Jinks",
                    "type": "MAIN",
                    "picture": "bf1a2f1e-7da1-4692-8a66-2bf96157c642"
                }],
                "album": {
                    "id": 182220040,
                    "title": "Less Wise",
                    "cover": "12193ada-c3f6-48f4-9fa0-d55cb2e0a43e",
                    "vibrantColor": "#FFFFFF",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/182220040",
                    "releaseDate": "2016-08-12"
                },
                "explicit": false,
                "volumeNumber": 1,
                "trackNumber": 3,
                "popularity": 44,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2021-05-01T00:00:00.000+0000",
                "editable": false,
                "replayGain": -10.58,
                "audioQuality": "LOSSLESS",
                "audioModes": ["STEREO"],
                "mixes": {
                    "TRACK_MIX": "001fffe9146518c56b9ad0d015c4a2"
                }
            }, {
                "id": 231866033,
                "title": "Numb",
                "duration": 156,
                "version": null,
                "url": "https://tidal.com/browse/track/231866033",
                "artists": [{
                    "id": 7250145,
                    "name": "Marshmello",
                    "type": "MAIN",
                    "picture": "a596f1fe-3e76-4314-8530-69b27fb93fa3"
                }, {
                    "id": 4916222,
                    "name": "Khalid",
                    "type": "MAIN",
                    "picture": "84e7a97a-e66c-48b3-ad88-2890066fb64e"
                }],
                "album": {
                    "id": 231866032,
                    "title": "Numb",
                    "cover": "703caf3c-8dc4-4836-a29e-aa44d9afedae",
                    "vibrantColor": "#9fd1df",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/231866032",
                    "releaseDate": "2022-06-10"
                },
                "explicit": false,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 68,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2022-06-10T00:00:00.000+0000",
                "editable": false,
                "replayGain": -9.46,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "0147bdf794b09b50b6d60f1d6fb903",
                    "TRACK_MIX": "00137d2d4dd1030005ef1ae2e64d21"
                }
            }, {
                "id": 138872432,
                "title": "I Look Good",
                "duration": 102,
                "version": null,
                "url": "https://tidal.com/browse/track/138872432",
                "artists": [{
                    "id": 5896451,
                    "name": "O.T. Genasis",
                    "type": "MAIN",
                    "picture": "6ac8210e-b1ed-4225-a44a-cbddd586d419"
                }],
                "album": {
                    "id": 138872431,
                    "title": "I Look Good",
                    "cover": "f406561e-a799-43de-9d1e-280b852a8cd3",
                    "vibrantColor": "#f9d46b",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/138872431",
                    "releaseDate": "2020-05-01"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 38,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2020-05-01T00:00:00.000+0000",
                "editable": false,
                "replayGain": -8.96,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "01452343b3589909390a4164019425",
                    "TRACK_MIX": "001f6cb8e851a11d9a68d80003f5f2"
                }
            }, {
                "id": 125093690,
                "title": "Red Line",
                "duration": 182,
                "version": null,
                "url": "https://tidal.com/browse/track/125093690",
                "artists": [{
                    "id": 8048820,
                    "name": "Geordie Kieffer",
                    "type": "MAIN",
                    "picture": null
                }],
                "album": {
                    "id": 125093689,
                    "title": "Red Line",
                    "cover": "b80983b9-f2a7-404e-b65f-1ed7860fea82",
                    "vibrantColor": "#b35e67",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/125093689",
                    "releaseDate": "2020-01-08"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 8,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2020-01-08T00:00:00.000+0000",
                "editable": false,
                "replayGain": -8.62,
                "audioQuality": "LOSSLESS",
                "audioModes": ["STEREO"],
                "mixes": {
                    "TRACK_MIX": "00104d152616c6579359939441ab42"
                }
            }, {
                "id": 215213468,
                "title": "Gospel",
                "duration": 210,
                "version": null,
                "url": "https://tidal.com/browse/track/215213468",
                "artists": [{
                    "id": 3963798,
                    "name": "Dr. Dre",
                    "type": "MAIN",
                    "picture": "1a705aec-4f48-40ba-a146-6f67e011680a"
                }, {
                    "id": 17275,
                    "name": "Eminem",
                    "type": "MAIN",
                    "picture": "480b074a-58da-469e-b4aa-d4e53fd1d5f5"
                }],
                "album": {
                    "id": 215213467,
                    "title": "Gospel",
                    "cover": "b32350b6-56e3-49cf-9207-a714ff91025e",
                    "vibrantColor": "#a6944d",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/215213467",
                    "releaseDate": "2022-02-04"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 58,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2022-02-04T00:00:00.000+0000",
                "editable": false,
                "replayGain": -10.74,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "014de0b796546a650cb74a3c7d3ed0",
                    "TRACK_MIX": "0013aa67e00d042e6608c9adb427c8"
                }
            }, {
                "id": 70870118,
                "title": "Sleeping on the Blacktop",
                "duration": 192,
                "version": null,
                "url": "https://tidal.com/browse/track/70870118",
                "artists": [{
                    "id": 6672522,
                    "name": "Colter Wall",
                    "type": "MAIN",
                    "picture": "a11692f6-e875-491f-bce4-0173f44ee7c1"
                }],
                "album": {
                    "id": 70870117,
                    "title": "Imaginary Appalachia",
                    "cover": "8da58d7c-a9d4-42a7-a135-712d60397f08",
                    "vibrantColor": "#e2d0af",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/70870117",
                    "releaseDate": "2018-01-19"
                },
                "explicit": false,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 39,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2017-03-03T00:00:00.000+0000",
                "editable": false,
                "replayGain": -7.13,
                "audioQuality": "LOSSLESS",
                "audioModes": ["STEREO"],
                "mixes": {
                    "TRACK_MIX": "001a2a053ac274a3ac80eb7e9d4d2a"
                }
            }, {
                "id": 237821203,
                "title": "Doja",
                "duration": 97,
                "version": null,
                "url": "https://tidal.com/browse/track/237821203",
                "artists": [{
                    "id": 8589558,
                    "name": "Central Cee",
                    "type": "MAIN",
                    "picture": "137e6101-36ec-4462-8d18-c6f374a3e4ca"
                }],
                "album": {
                    "id": 237821202,
                    "title": "Doja",
                    "cover": "a4739199-f51f-4e9d-8e15-4aef11330322",
                    "vibrantColor": "#c7d8e9",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/237821202",
                    "releaseDate": "2022-07-21"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 1,
                "popularity": 64,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2022-07-21T16:00:00.000+0000",
                "editable": false,
                "replayGain": -5.98,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "014d023089eade21828a9b11774c4e",
                    "TRACK_MIX": "001a920815b5f4d57efb6ce11ec78b"
                }
            }, {
                "id": 140490817,
                "title": "ooh la la (feat. Greg Nice & DJ Premier)",
                "duration": 181,
                "version": null,
                "url": "https://tidal.com/browse/track/140490817",
                "artists": [{
                    "id": 5171527,
                    "name": "Run The Jewels",
                    "type": "MAIN",
                    "picture": "4c4895e6-030f-4120-be39-ca840b3caad7"
                }, {
                    "id": 3604111,
                    "name": "El-P",
                    "type": "MAIN",
                    "picture": "9e6a524c-3fa2-4e1c-9aad-4e4b796073bb"
                }, {
                    "id": 5016,
                    "name": "Killer Mike",
                    "type": "MAIN",
                    "picture": "1ba6de84-bab8-433a-99e1-82d1781d412b"
                }, {
                    "id": 4082619,
                    "name": "DJ Premier",
                    "type": "FEATURED",
                    "picture": "f9c60d02-5eef-4662-8e58-e588e5e7b72f"
                }, {
                    "id": 3718662,
                    "name": "Greg Nice",
                    "type": "FEATURED",
                    "picture": "94047994-fc96-4410-b5d5-f126fdf8e7d4"
                }],
                "album": {
                    "id": 140490815,
                    "title": "RTJ4",
                    "cover": "b13d9c84-747d-47e6-b9f2-c23c71e62e81",
                    "vibrantColor": "#be1574",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/140490815",
                    "releaseDate": "2020-06-05"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 2,
                "popularity": 41,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2020-06-22T00:00:00.000+0000",
                "editable": false,
                "replayGain": -8.53,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "0140dec298c0e46db85d6ddba6dcba",
                    "TRACK_MIX": "0015622125d9f15c27c30b2dbf2fb8"
                }
            }, {
                "id": 52974885,
                "title": "Weight of Sound (feat. TJ O'Neill)",
                "duration": 443,
                "version": null,
                "url": "https://tidal.com/browse/track/52974885",
                "artists": [{
                    "id": 4942474,
                    "name": "Stick Figure",
                    "type": "MAIN",
                    "picture": "eb6ed2bf-a8ab-4f97-9d07-b60b97bab27f"
                }, {
                    "id": 4942475,
                    "name": "TJ O'Neill",
                    "type": "FEATURED",
                    "picture": null
                }],
                "album": {
                    "id": 52974879,
                    "title": "Burial Ground",
                    "cover": "525dbfa2-4d71-4078-96cf-0ba5804c3249",
                    "vibrantColor": "#ccbc85",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/52974879",
                    "releaseDate": "2012-01-01"
                },
                "explicit": false,
                "volumeNumber": 1,
                "trackNumber": 6,
                "popularity": 35,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2012-06-15T00:00:00.000+0000",
                "editable": false,
                "replayGain": -9.1,
                "audioQuality": "LOSSLESS",
                "audioModes": ["STEREO"],
                "mixes": {
                    "TRACK_MIX": "001b814bb26f42384d478f8f124133"
                }
            }, {
                "id": 86698003,
                "title": "It's Called: Freefall",
                "duration": 152,
                "version": null,
                "url": "https://tidal.com/browse/track/86698003",
                "artists": [{
                    "id": 5416094,
                    "name": "Rainbow Kitten Surprise",
                    "type": "MAIN",
                    "picture": "b3675173-8f39-48c9-8172-d0ea7c38cf78"
                }],
                "album": {
                    "id": 86697999,
                    "title": "How to: Friend, Love, Freefall",
                    "cover": "2612d792-a8cf-4e40-8df9-635485d2a263",
                    "vibrantColor": "#df9390",
                    "videoCover": null,
                    "url": "https://tidal.com/browse/album/86697999",
                    "releaseDate": "2018-04-06"
                },
                "explicit": true,
                "volumeNumber": 1,
                "trackNumber": 4,
                "popularity": 37,
                "allowStreaming": true,
                "streamReady": true,
                "streamStartDate": "2018-04-06T00:00:00.000+0000",
                "editable": false,
                "replayGain": -9.29,
                "audioQuality": "HI_RES",
                "audioModes": ["STEREO"],
                "mixes": {
                    "MASTER_TRACK_MIX": "014069ec04995575ebd2537f5a365a",
                    "TRACK_MIX": "001d91e79ca357d29a3ad505287121"
                }
            }],
            "dataApiPath": "pages/data/518d479b-3510-41ba-a62b-4c06055ec580?mixId=016574ac3abf29b2a6a1ae2c1b2f34"
        },
        "showTableHeaders": true
    }]
}]

}


Solution

  • .rows[] means something special to zsh.[1] You need to escape or quote so that .rows[] is passed to jq.

    jq '.rows[]' file.json
    

    1. I'm not familiar with zsh, so I don't know what it means, but that's not important here.