Skip to content

Instantly share code, notes, and snippets.

@domdorn
Created August 30, 2021 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domdorn/07880a3755213f9cb0804d2d245fd5a7 to your computer and use it in GitHub Desktop.
Save domdorn/07880a3755213f9cb0804d2d245fd5a7 to your computer and use it in GitHub Desktop.
JQ flatten / flatMap nested structure
{
"correlationId": "83937bab-e23c-465f-9708-5c0a0030cc6e",
"items": [
{
"jobId": "7601ebfa-fb17-41ad-815e-a7b6339952df",
"status": "Waiting",
"variants": [
{
"variantId": 1,
"status": "Waiting",
"calculations": [
{
"id": "7f61900f-6a4a-48db-b3c1-db53722b5065",
"status": "Waiting"
},
{
"id": "d0361a8a-81f1-4818-b961-d183ad318862",
"status": "Waiting"
}
]
}
]
},
{
"jobId": "2863a4a7-4fa6-4775-8868-b21f7c6c1c81",
"status": "Waiting",
"variants": [
{
"variantId": 1,
"status": "Waiting",
"calculations": [
{
"id": "7e787ee8-c86e-4f97-b04e-05411becc000",
"status": "Waiting"
},
{
"id": "9d99793e-436d-4f4b-8e4f-dc21cba5a3f7",
"status": "Waiting"
}
]
}
]
}
]
}
[.items[] | . as $job | .variants[] | . as $variant | .calculations[] | . as $calc | {"jobId": $job.jobId, "variantId": $variant.variantId, "calcId": $calc.id, "jobStatus": $job.status, "variantStatus": $variant.status, "calcStatus": $calc.status }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment