Created
May 9, 2017 03:04
-
-
Save arc279/24977d5e712f61e7d6b769867c3e9685 to your computer and use it in GitHub Desktop.
jq でキーと値を差し替える
This file contains hidden or 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
[ | |
{ | |
"id": "1-key", | |
"attr": "1-value" | |
}, | |
{ | |
"id": "2-key", | |
"attr": "2-value" | |
}, | |
{ | |
"id": "3-key", | |
"attr": "3-value" | |
}, | |
{ | |
"id": "4-key", | |
"attr": "4-value" | |
} | |
] |
This file contains hidden or 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
cat a.json | jq '[.[]|{(.id): .attr}]|add' |
This file contains hidden or 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
{ | |
"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