JSON Formatter

Format and validate JSON data with proper indentation

Transform messy JSON into clean, readable format with proper indentation and validation. Perfect for debugging API responses and cleaning up minified data.

Updated June 2026 · How this works

Example calculation — edit any field to use your own numbers

—

Put this calculator on your site

Free embed code. Works anywhere. No signup.

Worth knowing
How It Works
The formula, explained simply

JSON formatting works like a syntax-aware pretty printer that rebuilds your data structure from scratch. When you paste messy JSON, the formatter first parses it with the browser's JSON parser, validating every bracket and quote along the way. Think of it as disassembling a compressed file and rebuilding it with proper spacing—the data stays identical, but the presentation becomes human-readable.

The parsing step catches syntax errors immediately because JavaScript engines are unforgiving about malformed JSON. A missing quote or trailing comma that might slip past a casual code review gets flagged instantly. Once parsing succeeds, the formatter lays out your own text again with consistent 2-space indentation and line breaks, copying every string, number and key exactly as you typed it.

Property validation happens automatically during this process. The formatter counts the top-level properties, or the items of a top-level array, giving you immediate feedback about your JSON structure. Unlike simple text formatting, this approach checks the syntax first: if the output appears, the JSON is valid.

When To Use This
Right tool, right situation

Use JSON formatting whenever you receive compressed or minified data from APIs, configuration files, or database exports. The tool is essential for debugging API responses where you need to inspect nested structures or verify data types. It's particularly valuable when working with third-party services that return single-line JSON responses.

Format JSON before code reviews to make diffs readable and help teammates understand data structure changes. The formatter runs in your browser and sends your JSON nowhere, but formatted data is easy to read over your shoulder, so take care with sensitive data on a shared screen.

Don't rely on formatting alone to fix fundamental data structure problems. If your JSON represents the wrong data model or contains inappropriate nesting, formatting won't solve the underlying design issues. The tool validates syntax and improves readability, but architectural problems require data restructuring, not just prettier formatting.

Common Mistakes
Why results sometimes look wrong

The biggest JSON formatting mistake is assuming that working code equals valid JSON. JavaScript accepts many syntax variations that break strict JSON parsing, including unquoted property names, single quotes, and trailing commas. Code that runs fine in your browser might fail spectacularly when processed by APIs or other systems expecting standard JSON.

Developers often paste JSON fragments instead of complete objects, then wonder why validation fails. JSON allows a single root value: usually an object wrapped in {} or an array wrapped in [], though a lone string, number, true, false or null is also valid JSON. Multiple top-level elements, even if individually valid, create parsing errors that no amount of formatting can fix.

Another common error involves mixing data types in ways that seem logical but break JSON conventions. Undefined values, JavaScript comments, and function definitions have no JSON equivalent and must be removed or converted before formatting. The formatter catches these issues during parsing, but fixing them requires understanding what valid JSON actually allows versus what JavaScript accepts.

The Math
Worked examples and deeper derivation

JSON formatting follows deterministic rules based on data structure depth and type classification. Each nesting level adds exactly 2 spaces of indentation, creating visual hierarchy that maps directly to object relationships. Arrays and objects trigger line breaks before and after their content, while primitive values (strings, numbers, booleans) stay inline.

The algorithm processes nested structures recursively, calculating indentation as 2 × depth level. A property three levels deep gets 6 spaces, maintaining consistent visual alignment regardless of content complexity. Strings are copied exactly as typed, escape sequences included.

Property counting operates on the parsed object's immediate keys, ignoring nested structures. An object with 3 top-level properties shows count=3 even if those properties contain complex nested arrays. This shallow counting helps developers quickly assess API response structure without getting lost in implementation details.

API Response Cleanup
Minified API response with user data and nested permissions
The formatter transforms compressed JSON into readable structure with proper indentation, making it easy to inspect user properties, nested arrays, and boolean flags. For the example data, the status shows 3 top-level properties: users, total and page.
Configuration File Formatting
Single-line configuration object with multiple settings
Raw config data becomes properly indented JSON with clear property hierarchy. The validation confirms syntax correctness and counts top-level configuration sections for quick overview.
Debug Data Structure
Nested object with arrays, strings, numbers, and booleans
Complex data structures become readable with consistent 2-space indentation. Each nesting level is clearly visible, making it simple to trace object relationships and spot data type patterns.
Expert Unlock
The thing most explanations skip

Many formatters parse JSON into objects and print them again, which can change your data: JavaScript puts integer-like keys such as 2 before other keys, rounds integers beyond 9,007,199,254,740,991 and prints 3.0 as 3. This formatter copies your own tokens instead, so key order, numbers and escapes stay exactly as typed. If an object repeats a key, both lines stay; RFC 8259 warns that software handles repeated keys unpredictably.

Why won't my JSON format properly?

What causes JSON syntax errors?
Common JSON errors are missing quotes around property names, trailing commas after the last array element, and unescaped quotes inside string values. Each property name must be wrapped in double quotes, and commas should only separate elements, never trail them.
How do I fix invalid JSON from APIs?
API responses sometimes include JavaScript comments or single quotes that break JSON parsing. Remove any // comments, replace single quotes with double quotes around strings, and ensure all property names use double quotes rather than being unquoted.
Why does my formatted JSON look different than expected?
Only whitespace changes: indentation and line breaks are rebuilt, while property order, numbers (3.0 stays 3.0) and string escapes stay exactly as you typed them.

Need something this doesn't cover?

Suggest a tool — we'll build it →