[英]Removing new line feed
我正在從Firebase下載數據,並將其導出到json。 在此之后,我嘗試將其上傳到bigquery中,但是我需要刪除換行符,以便大查詢接受它。
這就是我從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"}
這就是我需要的方式,但是除了手動執行之外,我一無所知。
{ "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" }
我正在使用python加載json,讀取它,然后編寫一個新的json,但找不到正確的代碼。 謝謝!
這是我的python代碼的大綱
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)
您可以使用str.replace()將新行替換為任何行:
new_json_str = old_json_str.replace('\n', ' ')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.