I'm exporting a dataframe to a JSON file, through these lines of code:
with open('example.json', 'w') as f:
for row in df3.iterrows():
row[1].to_json(f, orient=None, lines=False)
f.write("\n")
And it returns a file like this:
{"age":20,"city":"Burdinne","email":"[email protected]","name":"Zorita","phone":4565434645.0,"postal_code":42680.0,"regDate":"2015-06-14T12:12:00-07:00"}
{"age":22,"city":"Bharatpur","email":"[email protected]","name":"Mariam","phone":null,"postal_code":null,"regDate":"2016-10-14T18:52:48-07:00"}
{"age":28,"city":"Neerheylissem","email":"[email protected]","name":"Malik","phone":null,"postal_code":null,"regDate":"2016-09-20T18:06:55-07:00"}
{"age":24,"city":"San Fratello","email":"[email protected]","name":"Claire","phone":null,"postal_code":null,"regDate":"2016-12-29T09:49:13-08:00"}
{"age":30,"city":"La Cruz","email":"[email protected]","name":"Hilel","phone":null,"postal_code":null,"regDate":"2016-07-09T12:03:31-07:00"}
However, I would like that JSON file to be tabulated like this:
[
{
"name": "Zorita",
"email": "[email protected]",
"regDate": "2015-06-14T12:12:00-07:00",
"city": "Burdinne",
"age": 20,
"postal_code":42680,
"phone": 4565434645
},
{
"name": "Mariam",
"email": "[email protected]",
"regDate": "2016-10-14T18:52:48-07:00",
"city": "Bharatpur",
"age": 22
},
{
"name": "Malik",
"email": "[email protected]",
"regDate": "2016-09-20T18:06:55-07:00",
"city": "Neerheylissem",
"age": 28
},
{
"name": "Claire",
"email": "[email protected]",
"regDate": "2016-12-29T09:49:13-08:00",
"city": "San Fratello",
"age": 24
},
{
"name": "Hilel",
"email": "[email protected]",
"regDate": "2016-07-09T12:03:31-07:00",
"city": "La Cruz",
"age": 30
}
]
How could I do this? In my code I'm trying to put the line break with "\ n" but apparently I'm not doing it correctly