View My JSON
Skip to main content
Blog

How to format JSON: pretty print, minify, and sort keys

Format JSON from the command line, in JavaScript, or in the browser. Covers indentation, minifying, sorting keys, and what formatting never changes.

Most JSON you receive from a server is deliberately unreadable: one long line with no spaces, built for machines. Formatting it is the first thing you do when something looks wrong in an API response, a webhook body, or a log entry. This guide shows several ways to format JSON, from a terminal one-liner to a few lines of code, and explains what formatting does and does not change.

Sources and further reading

Try the JSON workspace