title: How I can I lazily read multiple JSON values from a file/stream in Python?
body: <p>I'd like to read multiple JSON objects from a file/stream in Python, one at a time. Unfortunately <code>json.load()</code> just <code>.read()</code>s until end-of-file; there doesn't seem to be any way to use it to read a single object or to lazily iterate over the objects.</p>
  
  <p>Is there any way to do this? Using the standard library would be ideal, but if there's a third-party library I'd use that instead.</p>
  
  <p>At the moment I'm putting each object on a separate line and using <code>json.loads(f.readline())</code>, but I would really prefer not to need to do this.</p>
  
  <h2>Example Use</h2>
  
  <h3>example.py</h3>
  
  <pre class="lang-python prettyprint-override"><code>import my_json as json
  import sys
  
  for o in json.iterload(sys.stdin):
      print("Working on a", type(o))
  </code></pre>
  
  <h3>in.txt</h3>
  
  <pre class="lang-js prettyprint-override"><code>{"foo": ["bar", "baz"]} 1 2 [] 4 5 6
  </code></pre>
  
  <h3>example session</h3>
  
  <pre class="lang-none prettyprint-override"><code>$ python3.2 example.py &lt; in.txt
  Working on a dict
  Working on a int
  Working on a int
  Working on a list
  Working on a int
  Working on a int
  Working on a int
  </code></pre>