适用于 Linux 的 JSON 命令行格式化工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5243885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:28:51  来源:igfitidea点击:

JSON command line formatter tool for Linux

linuxjson

提问by Siva

Is there an editor or tool for Linux command line to format JSON data?

是否有用于 Linux 命令行的编辑器或工具来格式化 JSON 数据?

回答by tjb

 alias pp='python -mjson.tool'
 pp mydata.json

From the first link in the accepted answer: http://ruslanspivak.com/2010/10/12/pretty-print-json-from-the-command-line/

从接受的答案中的第一个链接:http: //ruslanspivak.com/2010/10/12/pretty-print-json-from-the-command-line/

回答by gliptak

On Ubuntu jsonlint is provided by apt:python-demjson

在 Ubuntu 上,jsonlint 是由 apt:python-demjson

Usage:

用法:

$ sudo apt-get install python-demjson
$ jsonlint -f input.json > output.json

回答by knight9631

Add to vimrc:

添加到 vimrc:

" Format JSON data
map <C-F6> :%!python -m json.tool<CR>

And you can use the shortcut CTRL+F6 to format json data

并且可以使用快捷键CTRL+F6格式化json数据



Or just under vim's command mode:

或者就在 vim 的命令模式下:

%!python -m json.tool

回答by here

jq is a lightweight and flexible command-line JSON processor.

jq 是一个轻量级且灵活的命令行 JSON 处理器。

http://stedolan.github.io/jq/

http://stedolan.github.io/jq/

jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

jq 就像 sed 用于 JSON 数据——您可以使用它来切片、过滤、映射和转换结构化数据,就像 sed、awk、grep 和朋友让您处理文本一样轻松。

jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine, and expect it to work.

jq 是用可移植的 C 语言编写的,它的运行时依赖性为零。您可以下载一个二进制文件,将其 scp 到远处的机器上,并期望它能够工作。