title: How to use data from a JQ key to name a new JSON file
body: <p>I have been trying to modify the accepted code provided by @peak in this thread: <a href="https://stackoverflow.com/questions/28744361/split-a-json-file-into-separate-files">Split a JSON file into separate files</a>. I'm very grateful for this answer, as it saved me many hours.</p>
  <p>Both of the solutions provided in that thread produce exactly the results I expect and want <em>within</em> the resulting split files. However, the output files are named &quot;$key.json&quot;. I would like the file name to be the data contained in the first field of the output file.</p>
  <p>Each output file looks something like this:</p>
  <pre><code>{
    &quot;name&quot;: &quot;Bob Smith&quot;,
    &quot;description&quot;: &quot;(some descriptive text)&quot;,
    &quot;image&quot;: &quot;(link to an image file)&quot;,
    ...
  }
  </code></pre>
  <p>I have spent several hours trying to figure out how to get the output file names to be &quot;Bob Smith.json&quot;, &quot;Jane Doe.json&quot; etc., instead of &quot;0.json&quot;, &quot;1.json&quot;, etc. I have tried many different ways of modifying the output parameters <code>printf &quot;%s\n&quot; &quot;$item&quot; &gt; &quot;/tmp/$key.json&quot;</code> and <code>'{ print $2 &gt; &quot;/tmp/&quot; $1 &quot;.json&quot; }'</code> without any success. I am completely new to JQ, so I suspect that the solution may be very simple. But, without spending many more hours learning JQ, I don't think I will be able to find it on my own.</p>
  <p>For your convenience, here are the solutions from the previous thread:</p>
  <pre><code>   jq -cr 'keys[] as $k | &quot;\($k)\n\(.[$k])&quot;' input.json |
    while read -r key ; do
      read -r item
      printf &quot;%s\n&quot; &quot;$item&quot; &gt; &quot;/tmp/$key.json&quot;
    done
  </code></pre>
  <p>and</p>
  <pre><code>jq -cr 'keys[] as $k | &quot;\($k)\t\(.[$k])&quot;' input.json |
    awk -F\\t '{ print $2 &gt; &quot;/tmp/&quot; $1 &quot;.json&quot; }'
  </code></pre>
  <p>Can someone who is proficient in JQ please give me a hint? Thank you.</p>