title: Writing JSON to file - wrong format?
body: <p>In <code>Python</code>, I'm trying to take an <code>XML</code> file, process it, then output the data to a <code>JSON</code>.  The XML processing works fine, but I am having trouble properly formatting the JSON.  The output file looks more like a list with dictionaries inside of it, which makes sense because that's what the code actually does.  How can I make this a proper JSON file?</p>
  
  <pre><code>filename = 'data.json'
  
  d = []
  
  for elem in ET.fromstring(data).findall('.//table/row'):
          field1 = elem.get('field1')
          field2 = elem.get('field2')
          field3 = elem.get('field3')
          field4 = elem.get('field4')
          l = {'field1' : field1, 
               'field2' : field2, 
               'field3' : field3, 
               'field4' : field4}
          d.append(l)
  
  f_out = open(filename, 'w')
  json.dump(d, f_out)
  
  f_out.close()
  </code></pre>
  
  <p>The output file looks like this:</p>
  
  <pre><code>[{"field1": "field1", "field2": "field2", "field3": "field3", "field4": "field4"}, ... {"field1": "field1", "field2": "field2", "field3": "field3", "field4": "field4"}]
  </code></pre>
  
  <p>When I would expect it to look like:</p>
  
  <pre><code>{"field1": "field1", "field2": "field2", "field3": "field3", "field4": "field4"}, ... {"field1": "field1", "field2": "field2", "field3": "field3", "field4": "field4"}
  </code></pre>