title: How to insert a bash variable into a json string?
body: <p>I have a bash script that does a post request to a GraphQL endpoint. The post body is JSON. Basically within that JSON, I would like to replace a value of one key/value pair with a value from a bash variable. I've tried different combinations but all of them resulted to errors. Here's my code:</p>
  <pre><code>#!/bin/bash
  
  utc_format=$(date -v-2d -v-23H -u +&quot;%Y-%m-%dT%H:%M:%SZ&quot;)
  
  curl -v \
      -X POST \
      -H &quot;Content-Type: application/json&quot; \
      -H &quot;X-Auth-Email: email@email.com&quot; \
      -H &quot;X-Auth-key: $API_KEY&quot; \
      --data '{&quot;query&quot;: &quot;query { viewer { zones ( filter: { zoneTag_in: [ \&quot;abcde12345\&quot; ] } ) { firewallEventsAdaptive ( filter: { source: \&quot;waf\&quot; datetime_gt: &quot;'&quot;\&quot;$utc_format\&quot;&quot;'&quot; ruleId: \&quot;100000\&quot; action: \&quot;simulate\&quot; } orderBy: [ datetime_DESC ] limit: 100 ) { clientIP edgeResponseStatus metadata { key value } } } } }&quot;}' \
      https://api.api.com/graphql \
      | python -m json.tool &gt;&gt; curl_results
  </code></pre>
  <p>If you look at my code, the &quot;' at the end of datetime_gt is to close the '{&quot; in --data. Then before rule_id, I opened it up again with '&quot;. What am I doing wrong?? I probably checked this a hundred times. Every time I try a different formatting, a new error pops up. Currently (with the code pasted here), the error that I get is:</p>
  <pre><code>{
      &quot;data&quot;: null,
      &quot;errors&quot;: [
          {
              &quot;extensions&quot;: {
                  &quot;timestamp&quot;: &quot;2020-12-21T03:32:11.090255834Z&quot;
              },
              &quot;message&quot;: &quot;failed to recognize JSON request: 'invalid character '\&quot;' after object key:value pair'&quot;,
              &quot;path&quot;: null
          }
      ]
  }
  </code></pre>