I'm accessing an API that returns JSON with nested objects like this:
{
"9273": {
"status": "ok",
"tag": "group-8",
"name": "London"
},
"4029": {
"status": "unknown",
"tag": "group-12",
"name": "Tokyo"
},
"6322": {
"status": "ok",
"tag": "group-12",
"name": "Singapore"
},
"1038": {
"status": "unknown",
"tag": "group-19",
"name": "Melbourne"
},
"2938": {
"status": "ok",
"tag": "group-12",
"name": "New York"
}
}
I'm trying to parse the JSON using jq, regex, sed etc. in a Bash script, filter it on status (ok) and tag (highest group with an 'ok'), and flatten the matching objects to get a multi-line sorted string value of their name along with a static prefix (e.g. City).
Desired output below:
City: New York
City: Singapore
I'll appreciate any help in working this out.