I'm wondering how i can escape the newValue so jq replaces the value in :
#!/bin/sh
test="{ \"one.one\" : { \"version\" : \"0.0.1\" }, \"two.two\" : { \"version\" : \"0.0.2\" } }"
newvalue="3.3.3"
newjson=$(echo $test | jq '."two.two".version = "$newvalue" ')
echo $newjson
outputs:
{ "one.one": { "version": "0.0.1" }, "two.two": { "version": "$newvalue" } }
none of the escapes i tried \"
\'
around $newvalue seems to work
CodePudding user response:
First of all, to use a variable, it can't be in quotes. Replace
"$newvalue"
with
$newvalue
Secondly, you never set $newvalue
in the jq program. To achieve that, you can use the following:
--arg newvalue "$newvalue"