How to add a newline function to JSON using Python -


i have json had manipulate , code looks this. had manipulate data because of invalid part of data not use when uploading bigquery.

import json  open('firetobq_peripheral.json', 'r') in_file:     dicts = []     line in in_file.readlines() :          d = json.loads(line.strip())         if d.get('peripherals'):              del d['peripherals']         dicts += [d]  open('firetobq_peripheral5.json', 'w') out_file:     out_file.write(json.dumps(dicts))     out_file.write("\n") 

however out_file.write("\n") not making json write each set of data on newline has in previous jsons have worked on. know why happening , how around this? help.

i need data presented

{"appname": "dataworks", "foundedperipheralcount": 1, "version": "1.6.1(8056)", "devicetype": "iphone 6", "createdat": "2017-04-05t07:05:30.408z", "updatedat": "2017-04-05t07:08:49.569z",  "connectedperipheralcount": 1, "iosversion": "10.2.1"} {"objectid": "20h5hg2inb", "foundedperipheralcount": 0, "devicevendorid": "5b7f085e-b3b6-4270-97dc-f42903cdeac1", "version": "1.3.5(5801)", "devicetype": "iphone 6", "createdat": "2015-11-10t06:16:45.459z", "updatedat": "2015-11-10t06:16:45.459z", "connectedperipheralcount": 0, "iosversion": "9.1"} {"appname": "dataworks", "foundedperipheralcount": 2, "version": "1.6.2(8069)", "devicetype": "iphone 6s", "createdat": "2017-04-12t10:05:05.937z", "updatedat": "2017-07-06t07:33:02.006z", "connectedperipheralcount": 8, "iosversion": "10.2.1"} 

if wish write data have read in, need iterate on each dictionary in dicts:

with open('firetobq_peripheral5.json', 'w') out_file:     d in dicts:         out_file.write(json.dumps(d))         out_file.write("\n") 

if not required, json.dump best option.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -