Using jq to modify files
Insert/Append
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
OR
echo '{"hello": "world"}' | jq '. + {foo: "bar"}'
{
"hello": "world",
"foo": "bar"
}
And “directly” in a file:
jq '.path += { "claims": "bar" } ' file.json > file1.json && mv file1.json file.json
jq
can not edit in place.
Replace
echo '{"hello": "world"}' | jq '. + {hello: "bar"}'
Delete
echo '{"hello": "world", "foo": "bar"}' | jq '. | del(.foo)'