我正在从firebase下载数据,并将其导出到json中。在此之后,我尝试将其上传到bigquery中,但我需要删除大查询的新行提要才能接受它。
{ "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"}这是我需要它的方式,但不知道如何做,除了手动做它。
{"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"}我正在使用python加载json,读取它,然后编写一个新的,但是找不到正确的代码。谢谢!
下面是我的python代码的大纲
import json
with open('nospacetest.json', 'r') as f:
data_json=json.load(f)
#b= the file after code for no line breaks is added
with open('testnoline.json', 'w') as outfile:
json.dump=(b, outfile)发布于 2017-06-28 06:33:41
在两行之间阅读时,我认为输入格式可能是单个JSON数组,所需的输出是该数组元素的新行分隔的JSON表示形式。如果是这样的话,这可能就是我们所需要的:
with open('testnoline.json', 'w') as outfile:
for obj in data_json:
outfile.write(json.dumps(obj) + "\n")发布于 2017-06-28 06:10:48
您只需要确保当您将数据indent=None到json时,dump:
with open('testnoline.json', 'w') as outfile:
json.dump(data_json, outfile, indent=None)引用医生的话:
如果
indent是一个非负整数,那么JSON数组元素和对象成员就会用这个缩进级别很好地打印出来。缩进级别为0或负,将只插入换行符。None(默认值)选择最紧凑的表示形式。
https://stackoverflow.com/questions/44794782
复制相似问题