is this valid JSON? error: Content not allowed in prolog
is this valid JSON? error: Content not allowed in prolog
如何测试以下 JSON
文件的正确性?
在命令行中使用basex
:
thufir@dur:~/json$
thufir@dur:~/json$ ls
formatted.json raw.json
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> CREATE DATABASE db raw.json
"/home/thufir/json/raw.json" (Line 1): Content is not allowed in prolog.
>
> CREATE DATABASE db formatted.json
"/home/thufir/json/formatted.json" (Line 1): Content is not allowed in prolog.
>
> exit
Have fun.
thufir@dur:~/json$
我运行原始数据经过一个formatter使其更具可读性:
thufir@dur:~/json$
thufir@dur:~/json$ cat formatted.json
{
"1224083010015956992": {
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sun Feb 02 21:31:46 +0000 2020",
"in_reply_to_user_id_str": null,
"source": "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App<\/a>",
"retweeted_status": {
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sun Feb 02 20:53:32 +0000 2020",
"in_reply_to_user_id_str": null,
"source": "<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck<\/a>",
"retweet_count": 3,
"retweeted": false,
"geo": null,
"in_reply_to_screen_name": null,
"is_quote_status": false,
"id_str": "1224073388706189312",
"in_reply_to_user_id": null,
"favorite_count": 6,
"id": 1224073388706189312,
"text": "Myth of the 10x programmer:\n\nh......... particularly like the list of productivity improvement \"tools\" at the end.",
"place": null,
"lang": "en",
"favorited": false,
"possibly_sensitive": false,
鉴于在线解析器显示数据并可以探索节点,看不出问题所在。
已满:
https://gist.github.com/THUFIR/ab9e1f77af92d4d984b268434afc01dd.js
CREATE DATABASE
的引用文档:
Syntax CREATE DB [name] ([input])
The input can be a file or directory path to XML documents, a remote URL, or a string containing XML
如您所见,该命令需要一个 XML 文件,而不是 JSON 文件。
似乎有效:
thufir@dur:~/json$
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-----------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
2 database(s).
>
> exit
See you.
thufir@dur:~/json$
thufir@dur:~/json$ ls
createDB.xquery formatted.json raw.json
thufir@dur:~/json$
thufir@dur:~/json$ cat createDB.xquery
let $database := "db"
for $name in file:list('.', false(), '*.json')
let $file := file:read-text($name)
let $json := json:parse($file)
return db:add($database, $json, $name)
thufir@dur:~/json$
thufir@dur:~/json$ basex createDB.xquery
Stopped at /home/thufir/json/createDB.xquery, 5/14:
[db:open] Database 'db' was not found.
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> create database db
Database 'db' created in 269.32 ms.
>
> list
Name Resources Size Input Path
-----------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 0 4570
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
> exit
See you.
thufir@dur:~/json$
thufir@dur:~/json$ basex createDB.xquery
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-------------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 2 196469
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
>
并且该查询将 return 一个非常大的文档,太大而无法粘贴到这里。
只是想用 Java 完成上述操作。关于 JSON 与 XML 的观点是正确的。 (xquery
文件是 from 文档。)
只要格式化的 JSON
在目录中,似乎效果更好:
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-------------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 1 101838
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
> open db
Database 'db' was opened in 66.85 ms.
>
> xquery /
然后是 return 预期结果(完整的 JSON
)。
如何测试以下 JSON
文件的正确性?
在命令行中使用basex
:
thufir@dur:~/json$
thufir@dur:~/json$ ls
formatted.json raw.json
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> CREATE DATABASE db raw.json
"/home/thufir/json/raw.json" (Line 1): Content is not allowed in prolog.
>
> CREATE DATABASE db formatted.json
"/home/thufir/json/formatted.json" (Line 1): Content is not allowed in prolog.
>
> exit
Have fun.
thufir@dur:~/json$
我运行原始数据经过一个formatter使其更具可读性:
thufir@dur:~/json$
thufir@dur:~/json$ cat formatted.json
{
"1224083010015956992": {
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sun Feb 02 21:31:46 +0000 2020",
"in_reply_to_user_id_str": null,
"source": "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App<\/a>",
"retweeted_status": {
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sun Feb 02 20:53:32 +0000 2020",
"in_reply_to_user_id_str": null,
"source": "<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck<\/a>",
"retweet_count": 3,
"retweeted": false,
"geo": null,
"in_reply_to_screen_name": null,
"is_quote_status": false,
"id_str": "1224073388706189312",
"in_reply_to_user_id": null,
"favorite_count": 6,
"id": 1224073388706189312,
"text": "Myth of the 10x programmer:\n\nh......... particularly like the list of productivity improvement \"tools\" at the end.",
"place": null,
"lang": "en",
"favorited": false,
"possibly_sensitive": false,
鉴于在线解析器显示数据并可以探索节点,看不出问题所在。
已满:
https://gist.github.com/THUFIR/ab9e1f77af92d4d984b268434afc01dd.js
CREATE DATABASE
的引用文档:
Syntax
CREATE DB [name] ([input])
The input can be a file or directory path to XML documents, a remote URL, or a string containing XML
如您所见,该命令需要一个 XML 文件,而不是 JSON 文件。
似乎有效:
thufir@dur:~/json$
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-----------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
2 database(s).
>
> exit
See you.
thufir@dur:~/json$
thufir@dur:~/json$ ls
createDB.xquery formatted.json raw.json
thufir@dur:~/json$
thufir@dur:~/json$ cat createDB.xquery
let $database := "db"
for $name in file:list('.', false(), '*.json')
let $file := file:read-text($name)
let $json := json:parse($file)
return db:add($database, $json, $name)
thufir@dur:~/json$
thufir@dur:~/json$ basex createDB.xquery
Stopped at /home/thufir/json/createDB.xquery, 5/14:
[db:open] Database 'db' was not found.
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> create database db
Database 'db' created in 269.32 ms.
>
> list
Name Resources Size Input Path
-----------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 0 4570
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
> exit
See you.
thufir@dur:~/json$
thufir@dur:~/json$ basex createDB.xquery
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-------------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 2 196469
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
>
并且该查询将 return 一个非常大的文档,太大而无法粘贴到这里。
只是想用 Java 完成上述操作。关于 JSON 与 XML 的观点是正确的。 (xquery
文件是 from 文档。)
只要格式化的 JSON
在目录中,似乎效果更好:
thufir@dur:~/json$
thufir@dur:~/json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> list
Name Resources Size Input Path
-------------------------------------------------------------------------------
com.w3schools.books 1 6290 https://www.w3schools.com/xml/books.xml
db 1 101838
w3school_data 1 5209 https://www.w3schools.com/xml/note.xml
3 database(s).
>
> open db
Database 'db' was opened in 66.85 ms.
>
> xquery /
然后是 return 预期结果(完整的 JSON
)。