How to format large JSON file in command line

There are several tools that can be used to format the large json file.

Prettier (if you have node.js and npx installed):

npx run prettier input_json.json > formatted_json.json

With python:

cat input_json.json | python -m json.tool > formatted_json.json

# json.tool uses 4 spaces as indent by default, we can change it:
cat input_json.json | python -m json.tool --indent 2 > formatted_json.json

With jq:

jq '.' input_json.json > formatted_json.json

Reminder: to open a large file in vim / nvim it is better to run it with -u NONE: nvim -u NONE formatted_json.json.

profile for Boris Serebrov on Stack Exchange, a network of free, community-driven Q&A sites