title: How to parse a single line json file containing multiple objects
body: <p>I need to read some JSON data for processing. I have a single line file that has multiple JSON objects how can I parse this?</p>
  
  <p>I want the output to be a file with a single line per object.</p>
  
  <p>I have tried a brute force method that will use json.loads recursively to check if the json is valid but I'm getting different results every time I run the program</p>
  
  <pre><code>import json
  
  with open('sample.json') as inp:
  s = inp.read()
  
  jsons = []
  
  start, end = s.find('{'), s.find('}')
  while True:
   try:
      jsons.append(json.loads(s[start:end + 1]))
      print(jsons)
  except ValueError:
      end = end + 1 + s[end + 1:].find('}')
  else:
      s = s[end + 1:]
      if not s:
          break
      start, end = s.find('{'), s.find('}')
  
  for x  in jsons:
    writeToFilee(x)
  </code></pre>
  
  <p>The json format can be seen here
  <a href="https://pastebin.com/DgbyjAG9" rel="nofollow noreferrer">https://pastebin.com/DgbyjAG9</a></p>