title: The best way to provide a JSON InputStream
body: <p>In different languages I need to provide users with a stream of JSON objects with an interface similar to the following:</p>
  
  <pre><code>JSONObject json = stream.nextJSON();
  </code></pre>
  
  <p>Since it is a stream, each call will block until a full object has been retrieved. This means it makes no sense to try and encapsulate each JSON object inside a big array. An extra layer of structure and processing has to be added to the stream.</p>
  
  <p>I have thought of two options:</p>
  
  <ol>
  <li>Segmenting the stream with the null-termination character.</li>
  <li>Writing a primitive parser that understand JSON scope so can detect the end of an object.</li>
  </ol>
  
  <p>Each of the above have a number of potential issues to discuss: How will null-termination interact with the file system, socket or underlying streams in C++, Java and other languages? What edge cases would we need to take in to account when parsing? (different types of quote symbol might confuse a parser, for example). Furthermore, there might be alternatives to the two above.</p>
  
  <p>So the question is: <strong>What is the best way to provide a JSON InputStream?</strong></p>