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
🌐
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:
🌐
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.
🌐
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.
🌐
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:
Find elsewhere
🌐
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.
🌐
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.
🌐
GitHub
gist.github.com › carymrobbins › e2c65bb5d7e5dd23dacacc1b281f54da
Example of piping curl response body to jq, pretty-printing if it is JSON parseable, otherwise, outputting the raw response body. You can include additional information, like the HTTP version and response code. · GitHub
Example of piping curl response body to jq, pretty-printing if it is JSON parseable, otherwise, outputting the raw response body. You can include additional information, like the HTTP version and r...
🌐
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.
🌐
GitHub
github.com › mgdm › htmlq › issues › 5
pretty print as the default · Issue #5 · mgdm/htmlq
April 10, 2020 - You can force it to produce color even if writing to a pipe or a file using -C, and disable color with -M. • --ascii-output / -a: jq usually outputs non-ASCII Unicode codepoints as UTF-8, even if the input specified them as escape sequences (like "\u03bc"). Using this option, you can force jq to produce pure ASCII output with every non-ASCII character replaced with the equivalent escape sequence. • --unbuffered 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).
Author   carnott-snap