title: Merging filter-generated output with static JSON object using jq
body: <p>I'm trying to use <code>jq</code> to iterate over some delimited text files, and generate objects from the rows.</p>
  <p>I also want to add some &quot;static&quot; objects (<code>json</code> shell variable in the example below) to the generated results.</p>
  <p>I've come up with the below solution, which <em>does</em> produce the output I want. But, because I'm not very confident in jq, every time I solve a problem with it, it feels like a monkey banging on a typewriter rather than a carefully crafted answer. So, I'm imaginging this could be incorrect.</p>
  <p><strong>data.txt</strong></p>
  <pre><code>apple|fruit
  Tesla|car
  sparrow|bird
  </code></pre>
  <p>Test (bash shell):</p>
  <pre class="lang-sh prettyprint-override"><code>$ json='[
    { &quot;object&quot;: &quot;love&quot;, &quot;type&quot;: &quot;emotion&quot; },
    { &quot;object&quot;: &quot;Ukraine&quot;, &quot;type&quot;: &quot;country&quot; }
  ]'
  
  $ jq --slurp --raw-input --argjson extra &quot;$json&quot; '
  split(&quot;\n&quot;) |
  map(select(length&gt;0)) |
  map(split(&quot;|&quot;) | {
    object: .[0],
    type: .[1]
  }) as $data |
  $data + $extra' data.txt
  </code></pre>
  <p>Output:</p>
  <pre class="lang-json prettyprint-override"><code>[
    {
      &quot;object&quot;: &quot;apple&quot;,
      &quot;type&quot;: &quot;fruit&quot;
    },
    {
      &quot;object&quot;: &quot;Tesla&quot;,
      &quot;type&quot;: &quot;car&quot;
    },
    {
      &quot;object&quot;: &quot;sparrow&quot;,
      &quot;type&quot;: &quot;bird&quot;
    },
    {
      &quot;object&quot;: &quot;love&quot;,
      &quot;type&quot;: &quot;emotion&quot;
    },
    {
      &quot;object&quot;: &quot;Ukraine&quot;,
      &quot;type&quot;: &quot;country&quot;
    }
  ]
  </code></pre>
  <p>Is this efficient?</p>