3

How to format large JSON file in command line

 1 year ago
source link: https://serebrov.github.io/html/2023-06-11-format-json-command-line.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to format large JSON file in command line

Posted on 2023, Jun 11 One min read

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.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK