I have the following string:
barrelRepDoc='{"'"_id"'":"'"push_$systemName"'","'"source"'":"'"$systemName"'","'"target"'":"'"platform2ReplicationTargetBaseURL/$systemName"'","'"create_target"'":true,"'"continuous"'":true,"'"user_ctx"'":{"'"name"'":"'"admin"'","'"roles"'":["'"_admin"'"]},"'"owner"'":"'"admin"'"}'
And I'm passing that string as the -d parameter into a cURL string such as this:
barrelRepcURL="curl -u $username:$password -X POST couchURL/db -H 'Content-Type:application/json' -d '$barrelRepDoc'"
And I'm then executing the command on this line:
barrelRepcURLresponse=$($barrelRepcURL)
And I'm getting invalid JSON. However, if I print out $barrelRepcURL, I get a string that executes as it is supposed to when pasted into the terminal.
I would like feedback on the cURL command, which is why I'm using a string. (echo $barrelRepcURLresponse)
How can I include the barrelRepDoc within the cURL command string and keep valid JSON?
jqto generate the JSON:barrelRepDoc=$(jq -n --arg systemName foo '{_id: ("push_" + $systemName), source: $systemName, target: ("platform2ReplicationTargetBaseURL/" + $systemName), create_target: true, continuous: true, user_ctxa: { name: "admin", roles: ["_admin"]}, owner: "admin"}')(It looks much better with some whitespace in your script.)