title: Dump each element of list on new line (Python & JSON)
body: <p>I have a list of dictionaries of the form:</p>
  
  <pre><code>mylist = [{'name': 'Johnny', 'surname': 'Cashew'}, {'name': 'Abraham', 'surname': 'Linfield'}] 
  </code></pre>
  
  <p>and I am trying to dump that to a json this way:</p>
  
  <pre><code>with open('myfile.json', 'w') as f:
      json.dump(mylist, f)
  </code></pre>
  
  <p>but then the entire list is on one line in the json file, making it hardly readable (my list is in reality very long). Is there a way to dump each element of my list on a new line? I have seen <a href="https://stackoverflow.com/questions/17055117/python-json-dump-append-to-txt-with-each-variable-on-new-line">this post</a> that suggests using <code>indent</code> in this way:</p>
  
  <pre><code>with open('myfile.json', 'w') as f:
      json.dump(mylist, f, indent=2)
  </code></pre>
  
  <p>but then I get each element within the dictionaries on a new line, like that:</p>
  
  <pre><code>[
    {
      'name': 'Johnny',
      'surname: 'Cashew'
    },
    {
      'name': 'Abraham',
      'surname: 'Linfield'
    }
  ]
  </code></pre>
  
  <p>whereas what I am hoping to obtain is something like that:</p>
  
  <pre><code>[
    {'name': 'Johnny', 'surname': 'Cashew'},
    {'name': 'Abraham', 'surname': 'Linfield'}
  ]
  </code></pre>
  
  <p>Would someone have a hint? Many thanks!  </p>