Jaf*_*son 15 command-line software-recommendation json
我正在尝试使用一些 JSON 文件验证器。
我遇到过,jq但运行后jq . file.json我只得到了 JSON 格式的输出,而不是我文件中的 JSON 验证。
我想知道如何在 Ubuntu 中检查我的文件中的语法或验证 JSON 格式。请指教!
Byt*_*der 14
尝试jsonlint:
sudo apt install jsonlint
Run Code Online (Sandbox Code Playgroud)
基本使用语法是
jsonlint YOUR-FILE.JSON
Run Code Online (Sandbox Code Playgroud)
您可以通过键入man jsonlint或访问其在线联机帮助页来找到其手册:
摘录:
NAME
jsonlint - A JSON syntax validator and formatter tool
SYNOPSIS
jsonlint [-v][-s|-S][-f|-F][-ecodec]inputfile.json...
[...]
OPTIONS
The return status will be 0 if the file is legal JSON, or non-zero
otherwise. Use -v to see the warning details.
[...]
-v, --verbose
Show details of lint checking
-s, --strict
Be strict in what is considered legal JSON (the default)
-S, --nonstrict
Be loose in what is considered legal JSON
-f, --format
Reformat the JSON (if legal) to stdout
[...]
Run Code Online (Sandbox Code Playgroud)
因此,您可以通过检查 .json 的返回码来查看您的 JSON 是否有效jsonlint。您可以通过在echo $?之后立即运行(0=OK,1=invalid)或使用&&,||或对其进行评估来查看它if。
zat*_*ine 10
我尝试过jsonlint,但没有成功。
jq . may-file.json干得好!
希望此反馈有帮助。