title: Flatten nested JSON array with JQ
body: <p>I have a JSON in the following format:</p>
  
  <pre><code>{
    "@version": "2.7.0",
    "site": {
      "@name": "http://api:9999",
      "@ssl": "false",
      "alerts": [
        {
          "pluginid": "10094",
          "desc": "&lt;p&gt;Base64 encoded data was disclosed by the application/web server&lt;\/p&gt;",
          "instances": [
            {
              "uri": "http://api:9999",
              "method": "POST",
              "evidence": "DxyPP_YQ6qdWA_Kw_ZLgYilIkXCz93Xs1CeJPvg"
            },
            {
              "uri": "http://api:9999",
              "method": "POST",
              "evidence": "eyJuYmYiOjE121lMWF1siSG9tZUFwcCJdfQ"
            }
          ],
          "count": "37"
        }
      ]
    }
  }
  </code></pre>
  
  <p>I want to flatten the inner array - <code>.site.alerts.instances</code> to get the following JSON:</p>
  
  <pre><code>{
      "@name": "http://api:9999",
      "@ssl": "false",
      "alerts": [
        {
          "pluginid": "10094",
          "desc": "&lt;p&gt;Base64 encoded data was disclosed by the application/web server&lt;\/p&gt;",
          "uri": "http://api:9999",
          "method": "POST",
          "evidence": "DxyPP_YQ6qdWA_Kw_ZLgYilIkXCz93Xs1CeJPvg",
          "count": "37"
        },
        {
          "pluginid": "10094",
          "desc": "&lt;p&gt;Base64 encoded data was disclosed by the application/web server&lt;\/p&gt;",
          "uri": "http://api:9999",
          "method": "POST",
          "evidence": "eyJuYmYiOjE121lMWF1siSG9tZUFwcCJdfQ",
          "count": "37"
        }
      ]
    }
  </code></pre>
  
  <p>I was able to flatten the inner JSON array by using the following JQ pattern:</p>
  
  <pre><code>.site.alerts[] as $in | $in.instances[] as $h |  $in | del(.instances) as $in2 |  $h * $in2 
  </code></pre>
  
  <p>This gave me a very close result:</p>
  
  <pre><code>{
    "uri": "http://api:9999",
    "method": "POST",
    "evidence": "DxyPP_YQ6qdWA_Kw_ZLgYilIkXCz93Xs1CeJPvg",
    "pluginid": "10094",
    "desc": "&lt;p&gt;Base64 encoded data was disclosed by the application/web server&lt;/p&gt;",
    "count": "37"
  }
  {
    "uri": "http://api:9999",
    "method": "POST",
    "evidence": "eyJuYmYiOjE121lMWF1siSG9tZUFwcCJdfQ",
    "pluginid": "10094",
    "desc": "&lt;p&gt;Base64 encoded data was disclosed by the application/web server&lt;/p&gt;",
    "count": "37"
  }
  </code></pre>
  
  <p>But not a perfect result. The objects are not in an array, and fields from the parent object, which are not part of the array (e.g. <code>.site.@name</code>) are not included.</p>
  
  <p>Can you help me improve the JQ pattern I created?</p>
  
  <p>Thanks in advance!</p>