JSON command line formatter tool for Linux

LinuxJson

Linux Problem Overview


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

Linux Solutions


Solution 1 - Linux

 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/

Solution 2 - Linux

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

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 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.

Solution 3 - Linux

On Ubuntu jsonlint is provided by apt:python3-demjson

Usage:

$ sudo apt install -y python3-demjson
$ jsonlint -f input.json > output.json

Solution 4 - Linux

Add to vimrc:

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

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


Or just under vim's command mode:

%!python -m json.tool

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSivaView Question on Stackoverflow
Solution 1 - LinuxtjbView Answer on Stackoverflow
Solution 2 - LinuxhereView Answer on Stackoverflow
Solution 3 - LinuxgliptakView Answer on Stackoverflow
Solution 4 - LinuxYaohui.WView Answer on Stackoverflow