title: Using jq, how can I split a JSON stream of objects into separate files based on the values of an object property?
body: <p>I have a very large file (20GB+ compressed) called <code>input.json</code> containing a stream of JSON objects as follows:</p>
  
  <pre><code>{
      "timestamp": "12345",
      "name": "Some name",
      "type": "typea"
  }
  {
      "timestamp": "12345",
      "name": "Some name",
      "type": "typea"
  }
  {
      "timestamp": "12345",
      "name": "Some name",
      "type": "typeb"
  }
  </code></pre>
  
  <p>I want to split this file into files dependent on their <code>type</code> property: <code>typea.json</code>, <code>typeb.json</code> etc., each containing their own stream of json objects that only have the matching type property.</p>
  
  <p>I've managed to solve this problem for smaller files, however with such a large file I run out of memory on my AWS instance. As I wish to keep memory usage down, I understand I need to use <code>--stream</code> but I'm struggling to see how I can achieve this.</p>
  
  <p><code>cat input.json | jq -c --stream 'select(.[0][0]=="type") | .[1]'</code> will return me the values of each of the type properties, but how do I use this to then filter the objects?</p>
  
  <p>Any help would be greatly appreciated!</p>