Created
September 26, 2022 17:53
-
-
Save walquis/fb24850f16137a64931f61db0cc286ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/24698188/flatten-a-json-document-using-jq | |
I want to transform this... | |
{ | |
"Research Data Management": [ | |
{ | |
"id": 2597547, | |
"title": "Data Engineer, Research Data Management" | |
}, | |
{ | |
"id": 3580145, | |
"title": "DevOps, Research Data Management" | |
}, | |
{ | |
"id": 3671657, | |
"title": "Market Data Systems Engineer" | |
} | |
] | |
} | |
...to this: | |
{ | |
{ team: "Research Data Management", "id": 2597547, "title": "Data Engineer, Research Data Management" }, | |
{ team: "Research Data Management", "id": 3580145, "title": "DevOps, Research Data Management" }, | |
etc... | |
} | |
# Courtesy of Nick Prendergast, 1 April 2022 (no fooling) | |
# | |
jq '[. | to_entries[] | .key as $team | .value[] | { "team": $team } + .]' /tmp/data.json | |
[ | |
{ | |
"team": "Research Data Management", | |
"id": 2597547, | |
"title": "Data Engineer, Research Data Management" | |
}, | |
{ | |
"team": "Research Data Management", | |
"id": 3580145, | |
"title": "DevOps, Research Data Management" | |
}, | |
{ | |
"team": "Research Data Management", | |
"id": 3671657, | |
"title": "Market Data Systems Engineer" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment