<p>I'm working with a json document where the property keys are filenames, and the values are the intended content of those files, where the files are mostly Java properties files.</p>

<p>I'm writing a Bash script that produces a modified json, where the change is the text in a single "line" of the content of one of the json properties.  This is essentially changing the value of a single property in the embedded Java properties file.</p>

<p>If it matters, the json document is a kubernetes configmap, but that doesn't matter for the problem I'm having.</p>

<p>The process is essentially this:</p>

<pre><code>augfile=$(cat $outfile | sed -e "s/${property}[     ]*=.*$/${property}=${newValue}/")
kubectl get configmap $configmap -o json | jq ".data[\"$filename\"] = \"$augfile\"" | kubectl replace $configmap -f -
</code></pre>

<p>What I see in the output is this:</p>

<pre><code>+ kubectlidp dev2 get configmap onemapms-green-configs -o json
+ jq '.data["application.properties"] = "...
...
listprop    =\
abc=def,\
ghi=jkl,\
mno=pqr
..."'
+ kubectl replace &lt;configmapname&gt; -f -
jq: error: Invalid escape at line 2, column 1 (while parsing '"\
"') at &lt;top-level&gt;, line 129:
listprop    =\                     
</code></pre>

<p>It's clear that I have to modify the way I specify the "$augfile" value, but I'm lost in the quotes there.</p>

David M. Karr
<p>Although you can sometimes get away with using shell string interpolation to "construct" the jq program, it's almost always better to pass in the shell values using the jq command-line options --arg and/or --argjson, e.g. in your case (assuming your shell allows this style of quoting):</p>

<pre><code> jq --arg filename "$filename" --arg augfile "$augfile" '
   .data[$filename] = $augfile'
</code></pre>
