Write multiple lists to a JSON file in python
Question: Assume I have the following lists

    
    
    list1 = [{"created_at": "2012-01-31T10:00:04Z"},{"created_at": "2013-01-31T10:00:04Z"}] 
    list2 = [{"created_at": "2014-01-31T10:00:04Z"}] 
    

I can write the first list to a JSON file using
`json.dump(list1,file,indent=2)` and the result is

    
    
    [
      {
        "created_at": "2012-01-31T10:00:04Z"
      },
      {
        "created_at": "2013-01-31T10:00:04Z"
      }
    ]
    

My question is, how do I append the contents of the second list? if I simple
do `json.dump(list2,file,indent=2)`, it results in an invalid JSON file as
below.

    
    
    [
      {
        "created_at": "2012-01-31T10:00:04Z"
      },
      {
        "created_at": "2013-01-31T10:00:04Z"
      }
    ][
      {
        "created_at": "2014-01-31T10:00:04Z"
      }
    ]
    

**Edit** : The lists are created dynamically by parsing about 8000 files. The
above lists are just example. I could potentially be writing 8000 lists to the
JSON file, so simple appending will not work.


Answer: 
    In [1]: import json
    
    In [2]: list1 = [{"created_at": "2012-01-31T10:00:04Z"},{"created_at": "2013-01-31T10:00:04Z"}] 
    
    In [3]: list2 = [{"created_at": "2014-01-31T10:00:04Z"}] 
    
    In [4]: list1.extend(list2)
    
    In [5]: json.dumps(list1)
    Out[5]: '[{"created_at": "2012-01-31T10:00:04Z"}, {"created_at": "2013-01-31T10:00:04Z"}, {"created_at": "2014-01-31T10:00:04Z"}]'
    

or

    
    
    In [8]: json.dumps(list1 + list2)
    Out[8]: '[{"created_at": "2012-01-31T10:00:04Z"}, {"created_at": "2013-01-31T10:00:04Z"}, {"created_at": "2014-01-31T10:00:04Z"}]'
    

