Im trying to insert a string ("/rest/config/hostgroup/${HGID}") into a json file using jq within a bash script.
initially it threw:
jq: error: syntax error, unexpected '/' (Unix shell quoting issues?) at , line 1:
So I set the string to be a jq variable like this:
echo $HOSTJSON | jq --arg HGP "$HGPATH" .hostgroup.ref=[$HGP] > host1.json
This didn't error but does not insert anything into the json other than [] as though the HGP variable isnt being populated. Omitting the square brackets around HGP throws the below indicating an empty variable:
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at , line 1:
.hostgroup.ref=
jq: 1 compile error
I've tried this on the CLI and get the same results, can confirm HGPATH is populated:
echo $HGPATH
/rest/config/hostgroup/5
cat host.json | jq --arg HGP "$HGPATH" .hostgroup.ref=$HGP
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at <top-level>, line 1:
.hostgroup.ref=
jq: 1 compile error
$HGID is being pulled from a query earllier in the script and is just a number and $HOSTJSON is a large JSON string
HGPATH="/rest/config/hostgroup/${HGID}"
echo $HOSTJSON | jq --arg HGP "$HGPATH" .hostgroup.ref=[$HGP] > host1.json