JSON Formatter & Beautifier
Format, minify, sort keys, and validate JSON — all in your browser, nothing sent to any server
Formatted JSON will appear here.
You copy a JSON response from curl — one line, 2000 characters, no formatting. You need to see the structure: is data an array or an object? Is the error field present? You could pipe through jq . in the terminal, but you’re already in the browser and just want to paste, format, and read.
Why This Formatter (Not the JSON Formatter & Validator)
PureDevTools has two JSON formatting tools. This one is simple and fast — paste JSON, pick indentation (2-space, 4-space, tab), get formatted output with syntax highlighting. The JSON Formatter & Validator adds validation with error location, key sorting, and statistics. Use this tool for quick formatting; use the other when you need diagnostics.
What Is a JSON Formatter and Why Does It Matter?
JSON (JavaScript Object Notation) has become the universal language of data on the web. Every developer works with it daily — reading API responses, editing configuration files, scanning application logs, and building request payloads. But JSON generated by programs or transmitted over networks arrives compacted into a single dense line that is nearly impossible to read. A string like {"user":{"id":42,"name":"Alice","roles":["admin","editor"]},"ts":"2024-01-15T09:23:00Z"} tells you almost nothing about its own structure at a glance.
A JSON formatter — also called a JSON beautifier, JSON pretty printer, or JSON indenter — solves this problem instantly. It parses the compact text and re-serializes it with clean, hierarchical indentation that exposes the shape of your data: which keys belong to which objects, how deeply arrays are nested, and where each value lives in the tree. One click turns a wall of minified text into a readable, navigable document.
This tool handles four operations that developers use every day:
- Format adds indentation and line breaks. Choose 2-space (the web standard), 4-space (common in Python and Java), or tab indentation to match your project’s code style.
- Minify strips all unnecessary whitespace to produce the smallest valid JSON string — useful before committing production configs or sending data over the wire.
- Validate checks your JSON against the RFC 8259 specification and reports the exact line and column of any syntax error, so you find the problem in seconds rather than scanning the whole document.
- Sort Keys recursively alphabetizes every object key at every nesting level, creating deterministic output that eliminates key-ordering noise in diffs and version control.
Everything runs in your browser using native JavaScript — no data ever leaves your device.
JSON Beautifier vs JSON Minifier
These are two opposite operations on the same data:
JSON beautifier (the Format button) expands compact JSON by adding newlines and indentation. It makes JSON easy to read, inspect, and debug, but increases file size. Use it during development, debugging, and code review.
JSON minifier (the Minify button) strips all unnecessary whitespace — spaces, tabs, and newlines — from a JSON document to produce the smallest valid JSON string. This reduces payload size for API responses, configuration files, and data stored in databases. Use it before committing production configurations or shipping data over the network.
Example — the same JSON before and after formatting:
{"name":"Alice","age":30,"hobbies":["reading","coding"]}
After formatting with 2-space indentation:
{
"name": "Alice",
"age": 30,
"hobbies": [
"reading",
"coding"
]
}
JSON Validator
The built-in JSON validator checks your JSON for syntax errors using the browser’s native JSON.parse function. When a problem is detected, the tool reports the exact line number and column where parsing failed — so you can jump directly to the problematic character without scanning the entire document.
Common JSON syntax errors include:
| Error | Example | Fix |
|---|---|---|
| Missing comma | {"a":1 "b":2} | Add , after 1 |
| Trailing comma | {"a":1,} | Remove the last , |
| Unquoted key | {name:"Alice"} | Quote the key: {"name":"Alice"} |
| Single quotes | {'name':'Alice'} | Use double quotes: {"name":"Alice"} |
| Mismatched bracket | {"a":[1,2} | Change } to ] |
| Undefined / comments | {"a": undefined} | JSON does not support undefined or comments |
| Bare number root | 0123 | Leading zeros are not valid in JSON numbers |
| Unescaped control character | {"msg":"line\none"} | Use \\n escape sequence instead of a literal newline |
Sort Keys Alphabetically
The Sort Keys feature recursively sorts all object keys in alphabetical order at every nesting level. Array element order is preserved — only object keys are sorted.
Sorting keys is useful for:
- Diffing — comparing two versions of a JSON document is much easier when keys appear in the same predictable order
- Version control — sorted keys eliminate spurious diffs caused by key reordering
- API response comparison — comparing responses from different endpoints or different API versions
- Readability — predictable key order makes large JSON objects easier to navigate
Common Use Cases
API development: Copy a JSON response from browser DevTools, Postman, Insomnia, or a curl command, paste it into the formatter, and instantly see the structure with syntax highlighting. Spot unexpected fields, missing keys, or wrong nesting immediately.
Configuration files: Format package.json, tsconfig.json, appsettings.json, .eslintrc.json, or any other JSON configuration file before committing to version control. Consistent indentation makes pull request reviews cleaner and reduces merge conflicts.
Log inspection: Application logs and event streaming systems often embed minified JSON payloads in log lines. Paste them here to inspect field values, trace IDs, error codes, and nested objects without straining your eyes.
Data validation before submission: Before sending JSON to an external API or storing it in a database, validate it here to catch syntax errors at your desk rather than debugging a 400 Bad Request at 2 am.
Comparing API responses: Format both responses, enable Sort Keys, then copy each into a diff tool. Sorted keys eliminate key-ordering noise so only real data changes appear in the diff.
Education and documentation: When writing API documentation or teaching JSON to junior developers, use the formatter to produce clean, consistently indented examples that are easy to read and copy.
Technical Reference
JSON Specification Compliance
This formatter implements the JSON grammar as defined in RFC 8259 (the current IETF standard, obsoleting RFC 7159 and the original RFC 4627) and ECMA-404 Second Edition (the Ecma International JSON Data Interchange Standard). These two documents are normatively equivalent and together define the canonical JSON specification used by all conforming parsers and generators worldwide.
Key specification rules this tool enforces:
- Strings must use double quotes —
"value", not'value' - Object keys must be double-quoted strings — bare identifiers like
{name: "Alice"}are JavaScript, not JSON - Numbers support integer, decimal, and scientific notation (
1,3.14,6.022e23) but notNaN,Infinity, or-Infinity(JavaScript-only values) - Booleans are lowercase —
trueandfalse, neverTrue,False,1, or0 - Null is the only null-like value —
undefinedis not a JSON type - Comments are not part of the specification — neither
//line comments nor/* */block comments - Trailing commas are not allowed —
[1, 2, 3,]is valid in JavaScript but invalid JSON - Root value can be any JSON value type — not just an object or array (a bare string
"hello"or number42is valid JSON) - Unicode is fully supported; strings may contain any Unicode code point except unescaped control characters (U+0000 through U+001F)
What This Tool Does Not Support
| Format | Description | Workaround |
|---|---|---|
| JSON5 | Superset with comments, trailing commas, single-quoted strings, unquoted keys | Remove non-standard syntax first |
| JSONC | JSON with Comments, used in VS Code settings.json and tsconfig.json | Strip // and /* */ comments before pasting |
| JSON Lines (JSONL / NDJSON) | One JSON value per line, no wrapping array | Validate and format each line individually |
| JavaScript object literals | undefined, NaN, Infinity, functions | Convert to valid JSON types first |
| BigInt | JavaScript integers beyond 2^53 - 1 may lose precision in JSON | Use string representation for large integers |
Formatting Options Reference
| Option | Values | Default | Notes |
|---|---|---|---|
| Indentation | 2 spaces / 4 spaces / Tab | 2 spaces | 2-space matches Prettier, ESLint, and Google Style Guide; 4-space matches Python json.dumps(indent=4) and many Java/C# conventions; Tab is required when .editorconfig or team style mandates it |
| Sort Keys | On / Off | Off | Alphabetizes object keys recursively at all nesting levels; array element order is always preserved |
| Output | Format / Minify | Format | Minify produces the smallest valid JSON with zero whitespace |
Browser-Side Processing
All operations — parsing, formatting, minifying, key sorting, and validation — execute entirely within your browser using the built-in JavaScript JSON.parse and JSON.stringify APIs, plus custom recursive sort logic for the Sort Keys feature. No network request is made at any point. The tool works offline after the initial page load. For very large documents (above 5 MB), performance depends on your device’s CPU speed and available memory, not on any server.
Frequently Asked Questions
What is the difference between JSON and JavaScript objects?
JSON is a strict text serialization format derived from JavaScript object literal syntax, but it has important restrictions that make it a proper data interchange format rather than code. All keys must be double-quoted strings. Values must be one of the six JSON types: string, number, object, array, boolean, or null. Features valid in JavaScript object literals but forbidden in JSON include: single-quoted strings, unquoted keys, trailing commas, undefined, NaN, Infinity, comments, and functions. These restrictions ensure that any conforming JSON parser — in Python, Go, Java, or any other language — can read the same document.
Why does JSON use double quotes and not single quotes?
The JSON specification (RFC 8259, Section 7) explicitly mandates double-quoted strings. Single-quoted strings are syntactically valid in JavaScript object literals but not in JSON. This is one of the most common mistakes when writing JSON by hand. Most JSON parsers in all languages will reject single-quoted strings with a syntax error, so it is important to use double quotes consistently.
Why does my JSON fail validation even though it looks correct?
Several hidden issues can cause JSON to fail despite looking fine visually. Common culprits include: a Byte Order Mark (BOM) at the start of the file (added by some Windows text editors), invisible Unicode characters such as non-breaking spaces (U+00A0) or zero-width spaces (U+200B), unescaped newlines or tabs inside string values (they must be written as \n and \t), and copy-paste artifacts from Word or rich text editors that replace straight quotation marks with typographic curly quotes (" and "). If your JSON fails and you cannot see why, try re-typing the problematic section manually.
What is the maximum JSON file size this tool can handle?
The formatter runs entirely in your browser using JavaScript’s built-in JSON.parse and JSON.stringify. It can comfortably handle JSON documents well over 1 MB without noticeable delay on modern hardware. For very large files (5 MB or more), consider disabling syntax highlighting and using the Minify output to reduce rendering work. Documents above 50 MB may approach browser memory limits, in which case a command-line tool such as jq is more appropriate.
Can I format JSON with comments (JSON5 or JSONC)?
No. Standard JSON does not support comments. RFC 8259 is explicit on this point. This tool validates strictly against the JSON specification. If your file contains // line comments or /* block comments */ (common in VS Code settings.json and TypeScript configuration files), you must remove the comments before pasting. Some editors can strip JSONC comments automatically — in VS Code, use the JSON: Remove Comments command or save the file as .json after stripping comments.
What does “Sort Keys” actually do to my data?
Sort Keys reorders the keys inside every JSON object alphabetically, at every nesting depth, before formatting or outputting the result. It does not change any values or modify arrays in any way — only object key order changes. The resulting JSON represents exactly the same data as the input; only the textual ordering of keys is different. This is useful because JSON objects are defined as unordered collections by the specification, meaning two JSON documents with the same keys in different orders are semantically identical. Sorting makes this semantic equivalence visible in diffs and version control.
What is the difference between RFC 8259 and ECMA-404?
RFC 8259 is published by the Internet Engineering Task Force (IETF) and is the document most web developers refer to when they say “the JSON spec.” ECMA-404 Second Edition is published by Ecma International and is the document the JavaScript standards body maintains. Both documents define the same grammar and are normatively equivalent — they were deliberately aligned to be interchangeable references. The practical difference is context: RFC 8259 is the IETF standard (used in HTTP, network protocols), while ECMA-404 is the Ecma standard (used in ECMAScript/JavaScript specifications).
Why does JSON not allow trailing commas?
Trailing commas — a comma after the last element in an array or the last key-value pair in an object — are forbidden by the JSON specification. This was a deliberate design choice when JSON was formalized, prioritizing strict, unambiguous parsing over developer convenience. JavaScript object and array literals allow trailing commas (and modern style guides encourage them for cleaner diffs), but JSON parsers in most languages will reject them. This mismatch is why copying JavaScript object literals into a JSON context often fails immediately.
Is my JSON data sent to any server?
No. Every operation — formatting, minifying, sorting, and validating — runs entirely in your browser using JavaScript. The tool makes no network requests with your data. Your JSON document never leaves your device. This means the tool is safe for formatting sensitive JSON such as API authentication tokens, database records, private configuration values, or any internal business data.
Can I format a JSON array at the root level?
Yes. A root-level JSON array is perfectly valid per the JSON specification. RFC 8259 defines the root value as any JSON value — object, array, string, number, boolean, or null. Paste [1, 2, {"key": "value"}, null, true] and the formatter will indent it exactly as it does for objects. The common misconception that JSON documents must start with { comes from older APIs that always returned objects; the specification itself imposes no such restriction.