0

I've searched for this and I while I'm sure its simple, I can't seem to get this to work. I need to loop through the JSON below in bash

{
    "data":
    [
        {
            "seen": true,
            "id": "2079a988-f856-4adb-bd3d-49ddf775ba16-1629277814281",
            "tinyId": "17290",
            "status": "closed",
            "acknowledged": false,
            "isSeen": true
        },
        {
            "seen": false,
            "id": "0a6e6024-9e80-42d2-ae4f-4b4af4a25fd2-1629277649193",
            "tinyId": "17289",
            "status": "open",
            "acknowledged": false,
            "isSeen": false
        },
        {
            "seen": false,
            "id": "108370f4-f54e-443d-9b7c-eec9d641c69a-1629277622211",
            "tinyId": "17288",
            "status": "open",
            "acknowledged": false,
            "isSeen": false
        }
    ]
}

The loop needs to read all the fields, so I can pass them to variables and check their values.

I've been trying with JQ and have tried

for x in "${json}"; do <something with "${x}">; done

and also

for x in "$(jq -r . <<< "${json}"); do <something with "${x}">; done

but it seems the output is not splitting.

Thanks,

Dave Shaw
  • 97
  • 1
  • 7
  • Is this any help? https://stackoverflow.com/a/68565565/2283 – Weeble Aug 18 '21 at 09:33
  • Unfortunately not. Those answers are regarding json in a file, my json is in a string. From a file it works: – Dave Shaw Aug 18 '21 at 09:55
  • If the linked answers don't answer your question, you can still edit it to explain why they're not useful and it might be re-opened. That said, the example I linked handles exactly the case you're describing - JSON in a bash variable. (Note that my link is not to the same question or answer as the one someone else used to close the question as a duplicate.) – Weeble Aug 18 '21 at 13:59

0 Answers0