【发布时间】:2019-07-27 06:53:50
【问题描述】:
我有一个以下格式的 JSON 文件:
/* 1 */
{
"input" : {
"text" : "car"
},
"output" : {
"text" : [
"Sorry! I didn't understand. Please rephrase."
],
},
"Auth" : "You are authenticated",
"Begin" : "Started",
"ID" : "ABC"
},
"timestamp" : ISODate("2017-02-20T12:36:40.226Z"),
}
/* 2 */
{
"input" : {
"text" : "bat"
},
"output" : {
"generic" : [
{
"response_type" : "text",
"text" : "I understood that!"
}
],
"text" : [
"I understood that!"
],
"log_messages" : []
},
"Auth" : "You are authenticated",
"Begin" : "Started",
"ID" : "CDE"
},
"timestamp" : ISODate("2016-02-20T12:36:40.226Z")
}
我想创建一个以下格式的数据框,但我不知道该怎么做(我不确定您是否必须清理 json 文件以不包含 cmets):
ID Date Input["text"] Output["text"]
ABC 2017-02-20 car Sorry! I didn't understand. Please rephrase.
CDE 2016-02-20 bat I understood that!
谁能帮忙?
【问题讨论】:
-
为什么要将对象存储在 JSON 文件中?对象应先解析成 JSON 格式。
-
这不是一个有效的 JSON 文件。不允许注释,文件应该是一个对象或数组。如果要存储多个对象,则应将它们包装在一个数组中。
-
对象的末尾还有一个额外的
,,ABC和CDE需要用引号引起来,而且大括号不匹配。 -
ISODate("2016-02-20T12:36:40.226Z")不是有效的 JSON -- JSON 没有函数调用。 -
如果你需要处理这个,你需要编写一个自定义解析器。它有很多问题,你无法使用标准的 JSON 解析器。
标签: python json python-3.x dataframe