Python json of a list
<p>I have a list of objects I defined.</p>

<p>At this moment I am iterating over every element in this list and dumping it into a file. But when I want to recreate the objects I run into problems:</p>

<pre><code>f = open(path, 'w')
for element in ListOfElements:
    json.dump(element.__dict__, f)
f.close()
</code></pre>

<p>When trying to recreate an object I do the following:</p>

<pre><code>a = json.JSONDecoder(object_hook = Element.from_json).decode(f.read())
</code></pre>

<p>But this is very bad as I must introduce some kind of splitters between the objects in the file. Then it would not be a "true" json anymore.
Is there a way to make some kind of</p>

<pre><code>json.dump(ListOfElements, f) #this exact code gives me "... is not JSON serializable"
</code></pre>

<p>which would then create a file that is able of recreating the entire list?</p>