title: How to iterate through chunks of a JSON object?
body: <p>I use the following function to chunk iterable python objects.  </p>
  
  <pre><code>from itertools import islice
  
  def chunked_iterable(iterable, chunk_size):
      it = iter(iterable)
      while True:
          chunk = tuple(islice(it, chunk_size))
          if not chunk:
              break
          yield chunk
  </code></pre>
  
  <p>I'm looking to do something similar with a basic JSON file.</p>
  
  <pre><code>[
      {object1: 'object1'},
      {object2: 'object2'},
      {object3: 'object3'},
      {object4: 'object4'},
      {object5: 'object5'},
      {object6: 'object6'},
      etc...
  ]
  </code></pre>
  
  <p>Like this.</p>
  
  <pre><code>from pathlib import Path
  import json
  
  def json_chunk(json_array_of_objects, object_count):
      # What goes here?
  
  if __name__ == '__main__':
      with open(Path(__file__).parent / 'raw_data.json') as raw_data:
          json_data = json.load(raw_data)
  
      for json_array_with_five_objects in enumerate(json_chunk(json_data, 5)): 
          for object in json_array_with_five_objects:
              print(object[0])
  </code></pre>
  
  <p>Is the term I'm looking for "streaming" JSON data?<br>
  How do you stream JSON data?</p>
  
  <p>As a learning exercise I'm trying to stick with base python functionality for now but answers using other packages are helpful too.</p>