嗨,我似乎无法使用python将json数据转换为csv,请帮助:
{
"metadata": {
"application": "orders-prod",
"host": "ldn001"
},
"OrdID": "123",
"EventSeq": "328",
"EventTS": "2019-04-17T01:01:14.569000Z"
}
{
"metadata": {
"application": "orders-prod",
"host": "ldn001"
},
"OrdID": "234",
"EventSeq": "328",
"EventTS": "2019-04-17T01:01:14.569000Z"
}
{
"metadata": {
"application": "orders-prod",
"host": "ldn001"
},
"OrdID": "554",
"EventSeq": "328",
"EventTS": "2019-04-17T01:01:14.569000Z"
}
df=pd.read_json('smallordersl.json',lines=True)
我尝试了上述操作,但不起作用-我收到错误ValueError:预期的对象或值。
答案 0 :(得分:0)
您的json文件不是您指定的每行。请参阅文档中有关读取json文件的以下说明。 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_json.html
lines : boolean, default False
Read the file as a json object per line.
下面是在参数中使用lines = True的示例
pd.read_json('{"a":1,"b":2}\n{"a":3,"b":4}', lines=True)
请注意,上面的json文件具有第1行和第2行,并用新行(\ n)分隔