Modify a key-value in a json using jq in-place

Use a temporary file; it’s what any program that claims to do in-place editing is doing. tmp=$(mktemp) jq ‘.address = “abcde”‘ test.json > “$tmp” && mv “$tmp” test.json If the address isn’t hard-coded, pass the correct address via a jq argument: address=abcde jq –arg a “$address” ‘.address = $a’ test.json > “$tmp” && mv “$tmp” … Read more

Accessing a JSON object in Bash – associative array / list / another model

If you want key and value, and based on How do i convert a json object to key=value format in JQ, you can do: $ jq -r “to_entries|map(\”\(.key)=\(.value|tostring)\”)|.[]” file SALUTATION=Hello world SOMETHING=bla bla bla Mr. Freeman In a more general way, you can store the values into an array myarray[key] = value like this, just … Read more