Skip to content
Advertisement

How to add a newline function to JSON using Python

I have a JSON that I had to manipulate and the code looks like this. I had to manipulate the data because of an invalid part of the data that I could not use when uploading to BigQuery.

JavaScript

However out_file.write("n") is not making the JSON write each set of data on a newline like it has in the previous JSONs I have worked on. Does anybody know why this is happening and how to get around this? Thanks for the help.

I need the data to be presented like this

JavaScript

Advertisement

Answer

If you wish to write your data exactly as you have read it in, then you will need to iterate over each dictionary in dicts:

JavaScript

If this is not required, then json.dump would be the best option.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement