title: Pretty Print multiple occurrences of JSON data in a file to an output file
body: <p>I am trying pretty print a JOSN data file with multiple occurrences of the following data below using the pprint function. </p>
  
  <p><strong>Content of data file</strong></p>
  
  <blockquote>
    <p>{"_abcd": {"options": {}, "module": "xxxx", "crawler": "1234567890"}, "hash": 1048951621, "os": null, "ip": sgdgdfd, "isp": "ASGSFDF", "port": YYY, "hostnames": [], "location": {"city": "rtyf", "region_code": "00", "area_code": null, "longitude": 111.23344, "country_code3": "xyz", "country_name": "qazwsx", "postal_code": null, "dma_code": null, "country_code": "yy", "latitude": 1.11111}, "timestamp": "XXXXX", "domains": [], "org": "FFFFF", "data": "Unit ID: 0\n-- Slave ID Data: \t()\n\nUnit ID: 255\n-- Slave ID Data: \t()\n\n", "asn": "44444", "transport": "tcp", "ip_str": "1.2.3.4"}
    {"_abcd": {"options": {}, "module": "yyyy", "crawler": "999999"}, "hash": 35473835, "os": null, "ip": sgdgdfd, "isp": "TYUUF", "port": YYY, "hostnames": [], "location": {"city": "wewd", "region_code": "00", "area_code": null, "longitude": 222.3456, "country_code3": "xyz", "country_name": "qazwsx", "postal_code": null, "dma_code": null, "country_code": "yy", "latitude": 1.11111}, "timestamp": "XXXXX", "domains": [], "org": "DDDD", "data": "Unit ID: 0\n-- Slave ID Data: \t()\n\nUnit ID: 255\n-- Slave ID Data: \t()\n\n", "asn": "44444", "transport": "tcp", "ip_str": "4.3.2.1"}
    ...more of the same data as above</p>
  </blockquote>
  
  <p>I found the code in this forum and modified it to write the output to a file:</p>
  
  <pre><code>import json
  from pprint import pprint
  
  with open('data.json') as data_file:    
  data = json.load(data_file)
  
  with open('outfile.json,'w') as data_out
  
  pprint(data,stream=data_out)
  </code></pre>
  
  <p>It works fine if the date file contains just 1 occurrence of the data and will fail when it has multiple occurrences.</p>
  
  <p>How to modify the code to make it work with multiple occurrences of my data?</p>