title: how to replace entire array using jq in shell script?
body: <p>Having the following structure:</p>
  
  <pre><code>{
    "DistributionConfig": {
      "DefaultCacheBehavior": {
        "LambdaFunctionAssociations": {
          "Quantity": 3,
          "Items": [
            {
              "LambdaFunctionARN": "3",
              "EventType": "origin-response",
              "IncludeBody": false
            },
            {
              "LambdaFunctionARN": "2",
              "EventType": "viewer-request",
              "IncludeBody": false
            },
            {
              "LambdaFunctionARN": "1",
              "EventType": "origin-request",
              "IncludeBody": false
            }
          ]
        }
      }
    }
  }
  </code></pre>
  
  <p>I extracted the items and modified them using the following:</p>
  
  <pre><code>export lambdaFunctionAssociations=$(echo $json |  jq '.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Items' |
   jq 'map(if .EventType == "origin-response"
            then . + {"LambdaFunctionARN":'$originResponse'}
            else .
            end
           )'  |
  jq 'map(if .EventType == "viewer-request"
            then . + {"LambdaFunctionARN":'$viewerRequest'}
            else .
            end
           )' |
  jq 'map(if .EventType == "origin-request"
            then . + {"LambdaFunctionARN":'$originRequest'}
            else .
            end
           )')
  </code></pre>
  
  <p>Now I have the following stored in lambdaFunctionAssociations:</p>
  
  <pre><code>[
    {
      "LambdaFunctionARN": "ZZZ",
      "EventType": "origin-response",
      "IncludeBody": false
    },
    {
      "LambdaFunctionARN": "YYY",
      "EventType": "viewer-request",
      "IncludeBody": false
    },
    {
      "LambdaFunctionARN": "XXX",
      "EventType": "origin-request",
      "IncludeBody": false
    }
  ]
  </code></pre>
  
  <p>I want to replace the "Items": in the org json trying this:</p>
  
  <pre><code>export updatedCloudFrontConf=$(echo $json | jq '.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Items='$lambdaFunctionAssociations'')
  </code></pre>
  
  <p>with thefollowing error: </p>
  
  <pre><code>jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at &lt;top-level&gt;, line 1:
  .DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Items=[
  </code></pre>