Free · Fast · Privacy-first

JSON Pretty Printer

"Pretty print" is the developer shorthand for formatting JSON with proper indentation so the nested structure is easy to read and navigate.

Pretty prints in one click

🔒

Validates before printing

Configurable indentation

No server, fully private

Cost
Free forever
Sign-up
Not required
Processing
In your browser
Privacy
Files stay local
FreeNo signupWhite-label

Add this JSON Formatter to your website

Drop the JSON Formatter into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.

  • Files stay 100% in the visitor's browser
  • Responsive — adapts to any container width
  • Free forever, no API key needed

Embed code

<iframe
  src="https://www.fixtools.io/json/json-formatter?embed=1"
  width="100%"
  height="780"
  frameborder="0"
  style="border:0;border-radius:16px;max-width:900px;"
  title="JSON Formatter by FixTools"
  loading="lazy"
  allow="clipboard-write"
></iframe>

Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.

JSON.stringify(obj, null, 2), How JavaScript Pretty Prints Natively

JavaScript has had a built-in JSON pretty printer since ECMAScript 5, standardised in 2009. The JSON.stringify() function accepts three arguments: the value to serialise, a replacer (usually null to include all properties), and a space argument. When the space argument is a positive integer, JSON.stringify inserts that many space characters after each colon, after each comma, and at each new nesting level with a newline before the indentation. JSON.stringify(obj, null, 2) produces 2-space indented output. JSON.stringify(obj, null, 4) produces 4-space indented output. You can also pass a string as the space argument, for example the tab character "\t", to produce tab-indented output. The ECMAScript specification caps the integer form at 10 spaces maximum.

The same pattern exists in every major programming language with a standard JSON library. Python's json.dumps(obj, indent=2) behaves identically, inserting 2 spaces per nesting level. Ruby's JSON.pretty_generate(obj) defaults to 2-space indentation. Go's json.MarshalIndent(v, "", " ") takes a prefix string and an indent string as separate arguments. Java's Jackson library has ObjectMapper().writerWithDefaultPrettyPrinter(). These are all implementations of the same concept defined by the JSON specification: insert insignificant whitespace at the positions allowed between tokens so that a human reader can follow the nesting structure without a machine caring either way.

When you use FixTools as a JSON pretty printer, the underlying operation mirrors what JSON.stringify does natively in the browser. The input is first passed through JSON.parse() to validate it and convert it to a JavaScript data structure. If parsing succeeds, JSON.stringify() is called with your chosen indent value to produce the pretty-printed output string. The browser's native JSON engine handles both operations with high-performance compiled code, which is why formatting is instantaneous even for moderately large payloads. FixTools adds syntax colour-coding on top, which the raw stringify output does not include but which significantly aids navigation in large or deeply nested documents.

Pretty printers expose JSON spec edge cases that compact output hides. The number grammar in RFC 8259 forbids leading zeros (007 is invalid), hexadecimal literals (0xFF is invalid), and the JavaScript special values NaN, Infinity, and -Infinity. When a pretty printer chokes on a number that looks valid in source code, it is usually one of these. Strings have their own pitfalls: lone surrogate code points such as a high surrogate without its low pair are technically allowed by the standard but break many downstream parsers. Comments are not part of JSON at all, even though VS Code accepts them in tsconfig.json files because that file is treated as JSONC. A strict pretty printer reveals all of these issues by refusing to print the input, pointing you directly at the offending byte.

Key preservation deserves explicit treatment because it interacts with both human readability and machine determinism. JSON.stringify and Python json.dumps preserve the source key order for string keys in modern runtimes, which keeps related fields visually grouped in the pretty-printed output. Sorting keys alphabetically is sometimes preferable, especially for canonical hashing, deterministic diffs in code review, or comparing two documents that were built in different orders. Pass sort_keys=True in Python or use a key-sorted serialiser in JavaScript such as json-stable-stringify when determinism matters. For large objects with many keys, the readability cost of alphabetical sort is usually worth the determinism benefit because reviewers can find any key by binary scan rather than reading every parent context to predict where it lives.

How to use this tool

💡

Paste your JSON and use the Format button to pretty print it with your preferred indentation style.

How It Works

Step-by-step guide to json pretty printer:

  1. 1

    Paste your JSON string

    Paste the JSON you want to pretty print into the editor input area. The editor accepts any JSON regardless of its current formatting, including fully minified single-line JSON, partially indented JSON, and JSON with inconsistent whitespace throughout.

  2. 2

    Select indentation

    Choose 2 spaces, 4 spaces, or tabs from the indentation options. The default is 2 spaces, which is the most common setting for JavaScript and TypeScript projects. Select 4 spaces for Python-style output or tabs for Go-style output.

  3. 3

    Click Format

    FixTools validates the JSON and pretty prints it with your chosen indentation. The output appears immediately with syntax highlighting that colour-codes keys, string values, numbers, booleans, and structural characters for easy navigation.

Real-world examples

Common situations where this approach makes a real difference:

JavaScript developer

A developer building a Node.js script that fetches data from an external REST API logs the raw response body during development and sees a compressed single-line string. Running JSON.stringify(body, null, 2) in the console, or pasting the body into FixTools, reveals a nested "items" array where each item contains a "metadata" object with a "source" field the developer had not seen in the API documentation. Knowing this field exists allows them to write the correct property access path and prevents a runtime undefined error in production.

Teacher

A programming instructor uses pretty-printed JSON to explain data structure concepts to students who are new to REST APIs. By formatting sample responses from public APIs like the GitHub API or OpenWeatherMap API, the instructor produces clean indented examples that show nesting levels with visual clarity. Students can see the difference between a top-level field, a nested object field, and a field inside an array element without needing to understand parsing code first.

Mobile app developer

An iOS developer uses Xcode's network inspector to capture a backend API response during a debugging session. The response body is displayed as raw unformatted text in the inspector. Copying the response and pasting it into FixTools to pretty print it reveals that a field expected to contain a string array is actually a single comma-separated string. This explains exactly why the mobile client's array parsing code is failing and points to the backend endpoint that needs to be fixed.

Database administrator

A DBA exports a JSON document from a MongoDB collection and needs to review its full schema before writing a migration script. Pretty printing the exported document in FixTools reveals the complete key hierarchy, including several deeply nested sub-objects three levels below the root that would have required counting characters to find in the raw single-line output. The formatted view shows the correct field paths for the migration script without any manual parsing.

Pro tips

Get better results with these expert suggestions:

1

Use null as replacer to include all keys

JSON.stringify(obj, null, 2) passes null as the replacer argument, which tells stringify to include all enumerable own properties of the object. If you pass an array of strings as the replacer, only the keys named in that array appear in the output, which is useful for producing a focused subset view. For a complete pretty print that includes every field, null is the correct replacer value and the one you should use for debugging and documentation purposes.

2

Pretty print in browser console quickly

In any browser DevTools console, type JSON.stringify(someObject, null, 2) and press Enter to see a pretty-printed version of any JavaScript object that is in scope on the current page. This works without switching to an external tool and without installing anything. For objects already serialised as strings, use JSON.stringify(JSON.parse(jsonString), null, 2) to parse first and then pretty print.

3

The space limit is 10 in the spec

Per the ECMAScript specification, if you pass an integer greater than 10 to JSON.stringify as the space argument, it is silently clamped to 10 spaces. You cannot produce more than 10 spaces of indentation per level using the native stringify function. For unusual indentation widths, use a post-processing step or a formatter that applies custom indentation after the fact.

4

Pretty print for logging in Node.js

In Node.js scripts and server applications, console.log(JSON.stringify(data, null, 2)) pretty prints any JavaScript object to stdout with 2-space indentation. For production logging this adds verbosity, but during local development it makes deeply nested response objects, database query results, and configuration objects readable without switching to an external tool.

FAQ

Frequently asked questions

A JSON pretty printer takes a minified or raw JSON string and adds newlines and consistent indentation to make it easy for a human to read and navigate. It is the same operation as JSON beautification or formatting. The term comes from the general programming concept of "pretty printing", which describes displaying code or data in a visually structured human-readable form rather than the most compact machine-processable form. The output of a JSON pretty printer is always a valid JSON document that parses identically to the input.
Yes. JSON.stringify(obj, null, 2) produces a pretty-printed string with 2-space indentation. The first argument is the value to serialise. The second is the replacer, where null means include all enumerable own properties. The third is the space width. You can use any integer from 1 to 10, or a string such as a tab character. For an existing JSON string (not an object), use JSON.stringify(JSON.parse(jsonString), null, 2) to parse it first. For a quick visual check without writing code, paste the JSON into FixTools.
No. Pretty printing only adds whitespace characters: spaces, tabs, and newlines. The JSON remains syntactically valid according to RFC 8259 and the data it represents is unchanged. A JSON parser reading the pretty-printed output produces an identical data structure to one reading the original compact input. Key order, array order, string values, number values, boolean values, and null values are all preserved exactly.
The only difference is the number of space characters inserted at each indentation level. Both options produce valid JSON. Two-space indentation keeps lines shorter, which is better for deeply nested structures where wide indentation would push values far to the right. Four-space indentation is more visually prominent and is the convention in some communities, particularly Python projects that follow PEP 8. Most JSON formatters default to 2 spaces. The choice has no effect on parsing or data integrity.
Yes. Python provides the simplest option: python3 -m json.tool file.json prints indented JSON to stdout without installing anything beyond Python. Using Node.js: node -e "process.stdout.write(JSON.stringify(require('./file.json'), null, 2))" works on any system with Node installed. The jq tool, installable via brew, apt, or winget, uses jq . file.json and supports additional filtering. All three produce indented output and also validate the input.
JSON.stringify throws a TypeError with the message "Converting circular structure to JSON" when the input object contains a circular reference, meaning an object that holds a direct or indirect reference back to itself. JSON does not support circular references because it is a linear text format with no mechanism to represent shared object identity. To serialize objects with circular references, use a library like flatted or circular-json that represents cycles in a non-standard but recoverable format, and remove the circular structure before pretty printing with standard JSON.stringify.
Standard JSON.stringify does not sort object keys. The output key order follows the insertion order of the object's properties in memory. If you need alphabetically sorted keys in the pretty-printed output, pass an array of sorted key names as the replacer argument to JSON.stringify, or pre-process the object with a key-sorting function before passing it to stringify. Some formatters offer an optional key-sort toggle. Sorted key output is useful for deterministic diffs and for documentation that lists fields in alphabetical order.
There is no limit imposed by the JSON.stringify specification. The practical ceiling is determined by the JavaScript engine's maximum string length (approximately 2GB in V8, used by Chrome and Node.js) and the browser's available memory. Files up to tens of megabytes format in the browser without issues. For files over 100MB, a command-line tool is more appropriate because it can process the file as a stream without holding the entire formatted output in browser memory for DOM rendering.
JSON.stringify outputs object keys in the V8 JavaScript engine's enumeration order, which for most objects matches insertion order. However, integer-like keys (keys that are valid non-negative integers) are sorted numerically first before string keys, regardless of their insertion order. This is a JavaScript engine behaviour, not a JSON spec requirement. If key order is important, either use sorted key output explicitly or be aware that integer-like keys may be reordered.
Hashing the pretty-printed file and the minified original will never match because the documents differ by every whitespace character. If you need a stable hash that ignores formatting, hash the parsed canonical form rather than the raw text. A common approach is JSON.stringify(JSON.parse(input)) which produces a deterministic compact form, then SHA-256 over that. For absolute determinism across languages, use a canonical JSON library that sorts keys lexicographically, normalises numbers, and chooses a single Unicode escape strategy. Without a canonical step, even two pretty printers using the same indent setting can disagree on how to escape forward slashes, embedded non-ASCII, or the U+2028 line separator character, producing different bytes for semantically identical data.
No. The text you paste lives only in the textarea's in-memory DOM node and is not written to browser history, IndexedDB, or local storage by FixTools. Browser history records URLs you visit, not the contents of forms or textareas on those pages. However, two related risks deserve mention. If you have a clipboard manager such as Maccy, Ditto, or a synced clipboard like Apple Universal Clipboard, the pasted text may persist in that tool's history even after you close the tab. And if a browser extension has activeTab or clipboardRead permission on the FixTools origin, it can read what you paste. For high-sensitivity data, format offline with jq instead. Disable clipboard sync and clear your clipboard manager history after working with sensitive payloads as a basic hygiene step that costs nothing but plugs a real exfiltration path.

Related guides

More use-case guides for the same tool:

Ready to get started?

Open the full JSON Formatter — free, no account needed, works on any device.

Open JSON Formatter →

Free · No account needed · Works on any device