title: JQ - Merge two arrays
body: <p>I'm looking for JQ query that allows me to merge 2 arrays variables (not files) and also take me to overwrite first array with newer value from second array. For example:</p>
  
  <pre><code>#!/bin/bash -e
  
  firstArrayVariable='
      [
          {
              "Key": "A B",
              "Value": "1 2"
          },
          {
              "Key": "C D",
              "Value": "3 4"
          },
          {
              "Key": "E F",
              "Value": "5 6"
          },
          {
              "Key": "G H",
              "Value": "9 10"
          }
      ]
  '
  
  secondArrayVariable='
      [
          {
              "Key": "A B",
              "Value": "1 2"
          },
          {
              "Key": "C D",
              "Value": "3 4"
          },
          {
              "Key": "G H",
              "Value": "11 12"
          },
          {
              "Key": "J K",
              "Value": "15 16"
          }
      ]
  '
  
  jq \
      --compact-output \
      --raw-output \
      --arg jqSecondArrayVariable "${secondArrayVariable}" \
      '. + $jqSecondArrayVariable // empty' \
  &lt;&lt;&lt; "${firstArrayVariable}"
  </code></pre>
  
  <p>I could not get it to work and I got following error</p>
  
  <blockquote>
    <p>jq: error (at :19): array ([{"Key":"A ...) and string ("\n    [\n ...) cannot be added</p>
  </blockquote>
  
  <p><strong>What I expect the result of the merged array is</strong></p>
  
  <pre><code>[
      {
          "Key": "A B",
          "Value": "1 2"
      },
      {
          "Key": "C D",
          "Value": "3 4"
      },
      {
          "Key": "E F",
          "Value": "5 6"
      },
      {
          "Key": "G H",
          "Value": "11 12"
      },
      {
          "Key": "J K",
          "Value": "15 16"
      }
  ]
  </code></pre>
  
  <p>any helps would be very appreciated!</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>I tried to use <code>--argjson</code> as @peak suggested, it concatenate array but it could not merge 2 arrays. Result I got now is an array with duplicated objects</p>