본문 바로가기
Programming

edit json in bash

by Chan_찬 2020. 5. 31.
728x90
반응형

install jq

https://stedolan.github.io/jq/manual/

sudo apt-get install jq

사용방법

jsonStr='{ "key1": "value1", "key2": "value2", "key3": "value3" }'
jq 'del(.key3)' <<<"$jsonStr"
#output
{
  "key1": "value1",
  "key2": "value2"
}
jq '. + { "key4": "value4" }' <<<"$jsonStr"
#output
{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3",
  "key4": "value4"
}
jq '.key1 = "new-value1"' <<<"$jsonStr"
#output
{
  "key1": "new-value1",
  "key2": "value2",
  "key3": "value3"
}
728x90
728x90
BIG
Buy me a coffeeBuy me a coffee

댓글