Reputation: 779
I am in the process of downloading data from firebase, exporting it into a json. After this I am trying to upload it into bigquery but I need to remove the new line feed for big query to accept it.
This is how I receive it from firebase.
{
"ConnectionTime": 730669.644775033,
"objectId": "eHFvTUNqTR",
"CustomName": "Relay Controller",
"FirmwareRevision": "FW V1.96",
"DeviceID": "F1E4746E-DCEC-495B-AC75-1DFD66527561",
"PeripheralType": 9,
"updatedAt": "2016-12-13T15:50:41.626Z",
"Model": "DF Bluno",
"HardwareRevision": "HW V1.7",
"Serial": "0123456789",
"createdAt": "2016-12-13T15:50:41.626Z",
"Manufacturer": "DFRobot"}
{
"ConnectionTime": 702937.7616419792,
"objectId": "uYuT3zgyez",
"CustomName": "Relay Controller",
"FirmwareRevision": "FW V1.96",
"DeviceID": "F1E4746E-DCEC-495B-AC75-1DFD66527561",
"PeripheralType": 9,
"updatedAt": "2016-12-13T08:08:29.829Z",
"Model": "DF Bluno",
"HardwareRevision": "HW V1.7",
"Serial": "0123456789",
"createdAt": "2016-12-13T08:08:29.829Z",
"Manufacturer": "DFRobot"}
This is how I need it but can not figure out how to do this besides manually doing it.
{ "AppName": "DataWorks","ConnectionTime": 126.7699910402298,"CustomName": "28888 ","DeviceID": "DC0798BD-EDB5-491B-8744-526C98FCDCA1","FirmwareRevision": "1.98","HardwareRevision" : "null","Manufacturer": "Transducers Direct LLC","Model": "TDWLB200010013 ","PeripheralType" : "5","PeripheralUUID": "5BB621A7-4AB8-69CF-7E0B-318547DFCF6D","Serial": "0000028888","createdAt": "1970-01-01T02:14:52.142Z" } { "AppName" : "DataWorks","ConnectionTime" : 3922.534584999084,"CustomName" : "28888 ","DeviceID" : "DC0798BD-EDB5-491B-8744-526C98FCDCA1","FirmwareRevision" : "1.98","HardwareRevision" : "null","Manufacturer" : "Transducers Direct LLC","Model" : "TDWLB200010013 ","PeripheralType" : "5","PeripheralUUID" : "5BB621A7-4AB8-69CF-7E0B-318547DFCF6D","Serial" : "0000028888","createdAt" : "1970-01-01T03:35:51.795Z" }
I am using python to load the json, read it and then write a new one but can not figure out the right code. Thank you!
here is the outline for my python code
import json
with open('nospacetest.json', 'r') as f:
data_json=json.load(f)
#b= to file afte code for no line breaks is added
with open('testnoline.json', 'w') as outfile:
json.dump=(b, outfile)
Upvotes: 1
Views: 573
Reputation: 11560
you can replace new line with anything using str.replace():
new_json_str = old_json_str.replace('\n', ' ')
Upvotes: 2