Python: Writing multiple json object to a file; Later to be open and load via json.load
<p>I have constructed a json object from a data stream where each user will have a json object. </p>

<pre><code>{
    "entities": {
        "description": {
            "urls": []
        }
    },
    "utc_offset": -10800,
    "id"
    "name": "Tom",
    "hit_count": 7931,
    "private": false,
    "active_last_month": false,
    "location": "",
    "contacted": false,
    "lang": "en",
}
</code></pre>

<p>Objective: I want to construct a json file where each json object become a line in a file with the indentation. And when it comes to reading back the JSON file it can be read using with open:</p>

<p>for example: Following File</p>

<pre><code>[
{
    "entities": {
        "description": {
            "urls": []
        }
    },
    "utc_offset": -10800,
    "id"
    "name": "Tom",
    "hit_count": 7931,
    "private": false,
    "active_last_month": false,
    "location": "",
    "contacted": false,
    "lang": "en",
}
,
{
    "entities": {
        "description": {
            "urls": []
        }
    },
    "utc_offset": -10500,
    "id"
    "name": "Mary",
    "hit_count": 554,
    "private": false,
    "active_last_month": false,
    "location": "",
    "contacted": false,
    "lang": "en",
}
]
</code></pre>

<p>Above file can easily read by: </p>

<pre><code>with open(pathToFile) as json_file:
     json_data = json.load(json_file)
     for key in json_data:
         print key["id"]
</code></pre>

<p>But at the moment here is how I am writing constructing the json file: </p>

<pre><code>with open(root + filename + '.txt', 'w+') as json_file:
        # convert from Python dict-like structure to JSON format
        jsoned_data = json.dumps(data)
        json_file.write(jsoned_data)
        json_file.write('\n')
</code></pre>

<p>This gives me</p>

<pre><code>{
   indented json data
}
{
   indented json data
}
</code></pre>

<p>PS: notice brackets <code>[]</code> are not there along with <code>,</code></p>

<p>When you try to read this same code structure as </p>

<pre><code>with open(pathToFile) as json_file:
     json_data = json.load(json_file)
     for key in json_data:
         print key["id"]
</code></pre>

<p>you end up getting errors: 
<code>ValueError: Extra data: line 101 column 1 - line 1889 column 1</code></p>