title: How to create a list of JSON objects in Python 2.7
body: <p>I am converting an XML file to a JSON file. I do this by opening the xml, use the <code>xmltodict</code> module and then use the .get method to traverse the tree to the level I want. This level is the parents to the leaves. I then check on a certain condition that some of the leaves for each of these <code>task</code> is true and if it is then I use <code>json.dumps()</code> and write it to the file. The issue is (I think this is where it is stemming from) that when I only append one JSON object to the file, it doesn't append a comma to the end of the object because it thinks it is the only object. I tried combating this by appending a ',' at the end of each JSON object but then when I try to use the <code>json.loads()</code> method it gives me an error saying "No JSON object could be decoded". However when I manually append the '[' and ']' to the file it doesn't give me an error. My code is below and I'd appreciate any help/suggestions you have.</p>
  
  <pre><code>def getTasks(filename):
      f = open(filename, 'r')
      a = open('tasksJSON', 'w')
      a.write('[')
  
      d = xmltodict.parse(f)
      l = d.get('Project').get('Tasks').get('Task')
      for task in l:
          if (task['Name'] == 'dinner'):  #criteria for desirable tasks
              j = json.dumps(task)
              a.write (str(j))   
              a.write(',')         
  
      a.write(']')
      f.close()
      a.close()
  </code></pre>
  
  <p>This works and puts everything in <code>tasksJSON</code> but like I said, when I call</p>
  
  <pre><code>my_file = open('tasksJSON', 'r')
  data = json.load(my_file)           # LINE THAT GIVES ME ERROR
  </code></pre>
  
  <p>I get an error saying </p>
  
  <pre><code>ValueError: No JSON object could be decoded
  </code></pre>
  
  <p>and the output file contains:</p>
  
  <pre><code>[{"UID": "4", "ID": "14", "Name": "Design"},{"UID": "5", "ID": "15", "Name": "Basic Skeleton"}]
                                             ^
                                   this is the comma I manually inserted
  </code></pre>