我想知道,如果JSON Lines文件的结构如下:
{"structure1":"some kind of file header"}
{"structure2": [ {"key1":"aaa", "key2":"bbb"}, {"key1":"one", "key2":"two"}]
{"structure2": [ {"key1":"xxx", "key2":"yyy"}, {"key1":"first", "key2":"second"}]
{"structure3":"maybe some kind of file footer"}
它被认为是无效的JSONLines格式吗?我在http://jsonlines.org/查看了标准,但我无法看到任何方式。 谢谢。
答案 0 :(得分:0)
你的每一行都是有效的(但缺少一个'}'以及第二和第三的结尾)。
但如果你想将它们全部放在一个文件中,它将无效。它们必须是数组并用,
或带键/值的对象分隔(其中值可以是数组或对象)
数组示例:
[
{"structure1":"some kind of file header"},
{"structure2": [ {"key1":"aaa", "key2":"bbb"}, {"key1":"one", "key2":"two"}]},
{"structure2": [ {"key1":"xxx", "key2":"yyy"}, {"key1":"first", "key2":"second"}]},
{"structure3":"maybe some kind of file footer"}
]
或对象:
{
"structure1": "some kind of file header",
"structure2": [{
"key1": "aaa",
"key2": "bbb"
}, {
"key1": "one",
"key2": "two"
}],
"structure2": [{
"key1": "xxx",
"key2": "yyy"
}, {
"key1": "first",
"key2": "second"
}],
"structure3": "maybe some kind of file footer"
}
您可以在此网站上测试您的json以查看是否有效: http://www.jslint.com/或http://jsonlint.com/