Skip to content

Instantly share code, notes, and snippets.

@arc279
Created May 9, 2017 03:04
Show Gist options
  • Save arc279/24977d5e712f61e7d6b769867c3e9685 to your computer and use it in GitHub Desktop.
Save arc279/24977d5e712f61e7d6b769867c3e9685 to your computer and use it in GitHub Desktop.
jq でキーと値を差し替える
[
{
"id": "1-key",
"attr": "1-value"
},
{
"id": "2-key",
"attr": "2-value"
},
{
"id": "3-key",
"attr": "3-value"
},
{
"id": "4-key",
"attr": "4-value"
}
]
cat a.json | jq '[.[]|{(.id): .attr}]|add'
{
"1-key": "1-value",
"2-key": "2-value",
"3-key": "3-value",
"4-key": "4-value"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment