jq . file.json

is what I was looking for. I didn't realize that the . is a filter and not a placeholder for the piped in content:

.

The absolute simplest (and least interesting) filter is .. This is a filter that takes its input and produces it unchanged as output.

And the man page makes it clear that the filter is a required argument.

Answer from k0pernikus on Stack Exchange
Discussions

json - How to pretty print using jq, so that multiple values are on the same line? - Stack Overflow
I know both forms are valid, and that jq has a compact/pretty print mode. But is there something in-between? I'm looking to somehow format a larger json file that has many more array values than this, so that it's easily readable and printable. More on stackoverflow.com
๐ŸŒ stackoverflow.com
pipe - How to use `jq` in a shell pipeline? - Stack Overflow
How can I prevent this behavior so that I can use jq in a pipeline? Edit: it looks like this is no longer an issue in recent versions of jq. I have jq-1.6 now and the examples above work as expected. * (I realize this example contains a useless use of cat; it's for illustration purposes only) ... You need to supply a filter as an argument. To pass the JSON through unmodified other than the pretty printing ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
unix - How can I pretty-print JSON in a shell script? - Stack Overflow
As noted above, one of the problems ... a JSON pretty-printer is that it does not always emit JSON. E.g. 1e1000 becomes Infinity (whether using python 2.x or 3.x). 'jq .' always produces JSON, but it does not guarantee that very large (or very small values) are preserved exactly. 2015-09-04T02:54:25.623Z+00:00 ... If you use npm and Node.js, you can do npm install -g json and then pipe the command ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
json - How can I pipe jq output - DevOps Stack Exchange
I recently learned about an outstanding little tool, jq that allows you to pipe unformatted JSON output into it and then have that output reformatted and output to the screen in a very nicely forma... More on devops.stackexchange.com
๐ŸŒ devops.stackexchange.com
๐ŸŒ
jq
jqlang.org โ€บ manual
jq 1.8 Manual
You can force it to produce color even if writing to a pipe or a file using -C, and disable color with -M. When the NO_COLOR environment variable is not empty, jq disables colored output by default, but you can enable it by -C. Colors can be configured with the JQ_COLORS environment variable (see below). ... Use a tab for each indentation level instead of two spaces. ... Use the given number of spaces (no more than 7) for indentation. ... Flush the output after each JSON object is printed (useful if you're piping a slow data source into jq and piping jq's output elsewhere).
๐ŸŒ
Discoposse
discoposse.com โ€บ home โ€บ using jq to pretty print json output
Using jq to pretty print JSON output - DiscoPosse.com
November 12, 2017 - All we have to do to fix that up is to pipe the output from our cURL command to jq and we are able to see the pretty printed version of the JSON:
๐ŸŒ
LornaJane
lornajane.net โ€บ posts โ€บ 2024 โ€บ pretty-print-json-with-jq
Pretty-print JSON with jq | LornaJane
cat is a command to print the contents of the file to stdout. Itโ€™s a good way to get content into the start of a chain of commands. The | operator sends the output of the cat command into the next thing in the command. jq is a JSON tool, and the "." part is technically a filter โ€“ but it includes everything, so itโ€™s more like a not-filter. The output of jq is the same JSON that we put in, but itโ€™s pretty-printed.
๐ŸŒ
Shapeshed
shapeshed.com โ€บ jq-json
JSON on the command line with jq | George Ornbo
September 19, 2024 - This takes the entire input and sends it to standard output. Unless told not to jq will pretty print making JSON readable. jq '.' names.json [ { "id": 1, "name": "Arthur", "age": "21" }, { "id": 2, "name": "Richard", "age": "32" } ] Because jq is UNIX friendly it is possible to pipe data in and out of it.
Find elsewhere
๐ŸŒ
Today I Learned
til.hashrocket.com โ€บ posts โ€บ uvsd8l7zes-pretty-print-json-in-neovimvim-using-jq
Pretty-Print JSON in NeoVim/Vim using jq - Today I Learned
August 30, 2024 - jq is an amazing command line utility for processing, querying and formatting JSON. I use it all the time when I get a response from an API request and I want to extract information or simply to pretty-print it with colors. All you have to do is pipe the curl results into jq:
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-transform-json-data-with-jq
How To Transform JSON Data with jq | DigitalOcean
September 23, 2025 - By default, jq will pretty print its output. It will automatically apply indentation, add new lines after every value, and color its output when possible. Coloring may improve readability, which can help many developers as they examine JSON data produced by other tools.
๐ŸŒ
Kyle Howells Blog
ikyle.me โ€บ blog โ€บ 2024 โ€บ pretty-print-json-terminal
Pretty Print JSON in the Terminal - Kyle Howells
August 8, 2024 - This will print the JSON response in a readable, pretty-printed format. jq is actually meant not to pretty print json, but to transform and manipulate json data. The . argument to it tells it to return the input unchanged as the output.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ web โ€บ guide to linux jq command for json processing
Guide to Linux jq Command for JSON Processing | Baeldung on Linux
August 31, 2025 - We echo a simple JSON string and pipe it into our jq command. Then we use the identity filter โ€˜.โ€™ that takes the input and produces it unchanged as output with the caveat that by default jq pretty-prints all output.
๐ŸŒ
jq
jqlang.org โ€บ tutorial
Tutorial
GitHub returns nicely formatted JSON. For servers that don't, it can be helpful to pipe the response through jq to pretty-print it.
๐ŸŒ
It's FOSS
itsfoss.com โ€บ pretty-print-json-linux
How to Pretty Print JSON File in Linux Terminal
March 20, 2023 - If you want to modify the original JSON file with pretty print format, you can pipe the parsed output to a new file and then copy it to the original JSON file.
Top answer
1 of 16
5227

With Python 2.6+ or 3 you can use the json.tool module:

echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool

or, if the JSON is in a file, you can do:

python -m json.tool my_json.json

if the JSON is from an internet source such as an API, you can use

curl http://my_url/ | python -m json.tool

For convenience in all of these cases you can make an alias:

alias prettyjson='python -m json.tool'

For even more convenience with a bit more typing to get it ready:

prettyjson_s() {
    echo "$1" | python -m json.tool
}

prettyjson_f() {
    python -m json.tool "$1"
}

prettyjson_w() {
    curl "$1" | python -m json.tool
}

for all the above cases. You can put this in .bashrc and it will be available every time in shell. Invoke it like prettyjson_s '{"foo": "lorem", "bar": "ipsum"}'.

Note that as @pnd pointed out in the comments below, in Python 3.5+ the JSON object is no longer sorted by default. To sort, add the --sort-keys flag to the end. I.e. ... | python -m json.tool --sort-keys.

Another useful option might be --no-ensure-ascii which disables escaping of non-ASCII characters (new in version 3.9).

2 of 16
1657

You can use: jq

It's very simple to use and it works great! It can handle very large JSON structures, including streams. You can find their tutorials here.

Usage examples:

$ jq --color-output . file1.json file1.json | less -R

$ command_with_json_output | jq .

$ jq # stdin/"interactive" mode, just enter some JSON

$ jq <<< '{ "foo": "lorem", "bar": "ipsum" }'
{
  "bar": "ipsum",
  "foo": "lorem"
}

Or use jq with identity filter:

$ jq '.foo' <<< '{ "foo": "lorem", "bar": "ipsum" }'
"lorem"
๐ŸŒ
Nick Janetakis
nickjanetakis.com โ€บ blog โ€บ pretty-print-json-in-your-terminal-with-jq-or-python
Pretty Print JSON in Your Terminal with jq or Python โ€” Nick Janetakis
July 4, 2023 - I created a small ppjson script which is available in my dotfiles. It requires having jq installed and it will either use xclip or pbpaste depending on what OS you have. ... # Pretty print the contents of your clipboard with 2 spaces of indentation ppjson # Pretty print the content of a file ppjson data.json
๐ŸŒ
Codehannah
codehannah.nyc โ€บ posts โ€บ jq
Pipe it to jq ๏ฝœ Code Hannah
Different jq commands are โ€œpipedโ€ to JSON output. The simplest command (| jq) pretty prints the JSON output, which makes the JSON more readable.