9 min read
How to pretty print JSON
Pretty printed JSON keeps the same data but adds indentation and line breaks so humans can inspect it faster.
Table of contents
Overview
Pretty printing JSON means parsing valid JSON and writing it back with predictable indentation, line breaks, and spacing. It changes presentation, not the actual keys, values, arrays, or objects. This matters because developers rarely work with isolated examples. The same idea usually appears in API payloads, config files, logs, docs, test fixtures, browser behavior, and debugging sessions where a small misunderstanding can turn into wasted time.
Pretty printing is useful when you receive a single-line API response, review a webhook payload, read logs, compare configuration, or inspect nested data during support work. A practical approach is to identify the format, the boundary where the data moves, and the tool or code that reads it. Once those pieces are clear, the problem becomes easier to test and explain to another developer.
How it works in practice
The useful mental model is to separate syntax from meaning. Syntax tells you whether the text can be read by the expected parser. Meaning tells you whether the parsed value is correct for the application, API contract, user workflow, or security rule you are dealing with.
Example: {"user":{"id":7,"roles":["admin","editor"]}} becomes a readable tree where user, id, roles, and each array item appear on separate indented lines. When you review an example like this, look at the exact boundary: what the sender creates, what the receiver expects, and what transformations happen between them. Many bugs live in those handoff points rather than in the obvious field names.
Debugging workflow
Paste the payload, validate it, pretty print it, then scan from the top-level shape downward. Collapse your mental model by sections: metadata first, data arrays second, errors last. Keep one known-good example beside the failing example. Compare the smallest meaningful difference first: shape, header, casing, timestamp unit, encoding, status code, or validation rule. This avoids changing multiple things at once and losing the real cause.
For repeatable debugging, write down the input, expected output, actual output, and the exact environment. A request copied from production, a browser console, a CI job, and a local script can behave differently because each one adds different headers, timezones, credentials, encodings, or defaults.
Common mistakes
A formatter cannot rescue invalid JSON. If pretty printing fails, the next step is validation. Another mistake is assuming whitespace inside string values will be changed; it should not be. These mistakes are common because developer tools often show a simplified view of data. A formatted body, a copied command, or a decoded token is only one layer of the full system.
A good defensive habit is to verify the assumption closest to the failure. If parsing fails, validate syntax before changing business logic. If authorization fails, inspect headers and claims before rewriting the UI. If dates look wrong, confirm timezone and unit before changing storage.
Safe practices
Pretty printing can make secrets more visible in screenshots and tickets. Redact tokens, passwords, keys, and private identifiers before sharing formatted output. Security and correctness often overlap: a value that is malformed, expired, mis-encoded, or interpreted in the wrong context can become both a bug and a risk.
Before sharing examples, remove production secrets, personal data, internal hostnames, account IDs when possible, and any token-like values. Replace them with clear placeholders so the example remains useful without exposing live credentials or private data.
Tools and next steps
Use JSON Formatter to pretty print, JSON Validator when parsing fails, and JSON Minifier when the same payload needs to become compact again. In Orlixio, the most relevant tools for this topic are Json Formatter, Json Validator, Json Minifier. Use them to inspect the small piece of data in front of you, then return to your application code or API documentation with a clearer understanding of the issue.
A simple checklist works well: confirm the input format, validate or decode it, compare it with a known-good example, record the result, and only then change code. That keeps the workflow fast without turning a small data problem into a broad refactor.
Related guides
What is JSON and why developers use it
A practical explanation of JSON, where it appears in development, and why its simple structure made it the common language of APIs.
How to format JSON online
Learn when to format JSON, how online formatters work, and what to check when formatting fails.
How to validate JSON and fix common errors
A practical guide to JSON validation, parser messages, and the most common syntax mistakes developers run into.
FAQ
What is the first thing to check for how to pretty print json?
Start by confirming the actual input and the context where it is used. Most debugging gets easier once you know whether the problem is syntax, format, transport, validation, or trust.
Which Orlixio tools are most useful for this topic?
The most relevant tools are Json Formatter, Json Validator, Json Minifier because they help inspect, convert, validate, or explain the data involved.
Can I paste production data into online tools?
Avoid pasting live secrets, tokens, personal data, private headers, or sensitive production payloads into any online tool. Use redacted examples or test data when possible.
How should I share an example with another developer?
Share the smallest reproducible example, include the expected and actual result, and replace sensitive values with clear placeholders such as <token>, <email>, or <account-id>.