title: JSON python pretty print with custom encoder to file
body: <p>I'm looking to output a Python dictionary to a file using the json library with formatting such that lists are represented on the same line. </p>
  
  <p>I have tried making a custom encoder and using the ones I have found online as well such as the suggestion here: 
  <a href="https://stackoverflow.com/a/26512016/1411362">https://stackoverflow.com/a/26512016/1411362</a></p>
  
  <p>such that the final code line is: </p>
  
  <pre><code>import json
  
  
  data = {'a':1, 'b':[1,2,3,4]}
  with open("data.json", 'w') as f:
      json.dump(data, f, indent=4, cls=CustomEncoderClass)
  </code></pre>
  
  <p>however, this fails to work if I try to use json.dump to export as a file instead of json.dumps (like in the link above) to a string. Is there a way to use the custom encoder such that it works when I export the data to a file?</p>