JSON Formatter
Format, validate and minify JSON with syntax highlighting.
Reviewed by Aygul Dovletova · Last reviewed
How to Use the JSON Formatter
- Paste or type JSON into the large monospace textarea labelled "Paste your JSON here...". The field accepts API responses, log payloads, config files, or a single value such as
42or"hello". - Pick an indent from the dropdown on the right: 2 spaces (the community default, used by npm, prettier, and most REST APIs) or 4 spaces (more common in Python and some enterprise Java shops).
- Click Format to pretty-print with line breaks and indentation, or Minify to collapse everything onto one line and remove insignificant whitespace.
- Read errors if any appear. Invalid input surfaces the exact
SyntaxErrorfrom the engine, including the character position, so you can jump to the offending token. - Copy the output with the Copy button in the top right of the output panel, or select the rendered
<pre>block manually for partial copies.
What the Formatter Does Under the Hood
The formatter is a thin, honest wrapper around two built-in JavaScript methods: JSON.parse(input) followed by JSON.stringify(parsed, null, indent). When you click Format, the parser walks the string with the rules from ECMA-404 and RFC 8259, rejecting anything outside the JSON grammar. The resulting in-memory tree (objects, arrays, strings, numbers, booleans, and null) is then serialized back with the indent argument set to 2 or 4 spaces, which triggers the stdlib's line-break-per-key emission.
Minify calls JSON.stringify(parsed) with no indent argument, producing the most compact canonical form the spec allows. Because both paths go through a full parse, a successful output is also a valid-JSON certificate: malformed input cannot pretty-print. The whole pipeline executes on the JavaScript engine of the tab you have open (V8 in Chrome and Edge, SpiderMonkey in Firefox, JavaScriptCore in Safari), so there is no network request at format time and no server ever sees your payload.
When This Tool Earns Its Keep
- Inspecting a minified webhook body copied out of a proxy like Charles, mitmproxy, or a Cloudflare request log.
- Cleaning up a compact
package.json,tsconfig.json, or OpenAPI document before committing. - Shrinking a large configuration blob before embedding it in an environment variable or a query string.
- Double-checking that a hand-written JSON fixture parses before shipping it into a test suite.
- Explaining a nested GraphQL response to a teammate on a call, where readable indentation matters more than file size.
- Sanity-checking that a backend that claims to emit JSON does not secretly produce JSONP or JSON5.
Common Pitfalls and Edge Cases
- Trailing commas like
{"a":1,}are legal in JavaScript object literals and JSON5 but illegal in strict JSON. The parser rejects them with aSyntaxError. - Comments (
//or/* */) are never allowed in RFC 8259. Strip them before pasting if your source is a JSONC file liketsconfig.json. - Single quotes around keys or strings are invalid; only double quotes are accepted. Python
repr()output often hits this. - Unquoted keys such as
{name:"Ada"}parse in JS but not JSON. Quote every key. - NaN, Infinity, and
undefinedare not JSON values;JSON.parsethrows on them even though they are valid JavaScript. - Large numbers beyond
Number.MAX_SAFE_INTEGER(2^53 - 1) lose precision on parse. For order IDs or blockchain amounts, keep them as strings.
JSON in a Nutshell: RFC 8259 and ECMA-404
JSON (JavaScript Object Notation) was introduced by Douglas Crockford in the early 2000s and standardized twice, once by ECMA International as ECMA-404 and once by the IETF as RFC 8259 (which supersedes the older RFCs 4627 and 7159). The grammar is deliberately small: a value is an object, array, string, number, boolean, or null, with whitespace permitted anywhere outside a token. RFC 8259 mandates UTF-8 for network interchange, which is why servers that emit UTF-16 or Latin-1 JSON break clients. A well-formed JSON document is a single value, so a bare [1,2,3] is valid at the top level, not only wrapped in an object. Comments, trailing commas, and hex numbers are excluded on purpose; the simplicity is the feature.
Alternatives and When They Beat This Tool
Command-line jq is better when you need to query or transform JSON, not just reshape whitespace: it handles streaming over gigabytes and has a real query language. Python's python -m json.tool is handy in a terminal pipeline and is already installed on most Unix systems. IDE plugins like Prettier, VS Code's built-in Format Document, or JetBrains' JSON tool window format in place without copy-paste. A browser formatter like this one wins when you have a single blob in your clipboard, no shell open, and you do not want to paste sensitive data into a remote service like jsonformatter.org or online-json.com. For anything larger than roughly 20 MB, switch to a streaming parser such as jq, simdjson, or Node's stream-json package, since single-pass JSON.parse holds the entire parsed tree in tab memory.
Frequently Asked Questions
Does my JSON get sent to a server when I format it?
No. The Format and Minify buttons both call the browser-native <code>JSON.parse</code> and <code>JSON.stringify</code> functions on the page thread, and the rendered output is written straight into a DOM node. There is no <code>fetch</code> call, no WebSocket, and no service worker that intercepts the text. You can open DevTools, switch to the Network tab, and confirm it yourself, or run the page fully offline after the initial load.
Why does the parser reject my JSON when it looks fine?
The most common culprits are trailing commas, single quotes, unquoted keys, JavaScript-style comments, or stray BOM characters at the start of the file. Strict JSON is a subset of JavaScript object literal syntax, so anything a JavaScript programmer writes casually may not survive <code>JSON.parse</code>. The error message shows the character index, so count characters from the start or paste it into an editor with a ruler to find it fast.
What is the difference between format, minify, and lint?
Formatting only rewrites whitespace: keys, values, and ordering are preserved. Minifying also only touches whitespace, just in the opposite direction - it strips every character the spec marks as insignificant. Linting (jsonlint, ajv, or a JSON Schema validator) additionally checks semantic rules: required keys, data types, enum membership, regex patterns. This tool does the first two; it does not validate against a schema.
How big a JSON file can I paste in before the tab slows down?
The V8 and SpiderMonkey parsers handle several hundred megabytes in theory, but the tab has to hold the input string, the parsed tree, and the formatted output string all at once, so practical comfort tops out around 20 to 50 MB. Beyond that, use a streaming CLI tool like <code>jq</code> or write a small Node script with <code>stream-json</code>. Very large arrays also make the <code><pre></code> element sluggish because the browser lays out every line.
Does the formatter preserve the order of object keys?
Yes. ECMA-262 guarantees insertion order for string keys on plain objects, and both <code>JSON.parse</code> and <code>JSON.stringify</code> respect that ordering. If your input lists <code>"name"</code> before <code>"id"</code>, the output will too. Integer-like string keys, however, get sorted numerically by the JavaScript spec, which matters for keys like <code>"1"</code>, <code>"2"</code>, <code>"10"</code>.
Why does <code>JSON.parse</code> turn 18446744073709551615 into 18446744073709552000?
JSON numbers are parsed into JavaScript <code>Number</code> values, which are IEEE 754 double-precision floats with only 53 bits of integer precision. Anything above <code>Number.MAX_SAFE_INTEGER</code> (9007199254740991) loses low-order digits. Backends that emit 64-bit IDs, cryptocurrency amounts, or Unix nanosecond timestamps should encode them as strings; the formatter will round-trip the string faithfully.
Can I use this tool on JSON5, JSONC, or NDJSON?
Not directly. JSON5 allows comments, trailing commas, and unquoted keys; JSONC is JSON with comments (used by VS Code and TypeScript configs); NDJSON is one JSON document per line. The parser here implements strict RFC 8259, so any of the three will throw. Strip comments and trailing commas before pasting, or for NDJSON, format one line at a time.
What does the indent selector actually control?
It sets the third argument to <code>JSON.stringify</code>, which is either a number (how many spaces to insert per level) or a string (a literal indent prefix). The dropdown exposes 2 or 4 because those cover almost every style guide. If you need tabs, copy the 2-space output and run a find-replace; the formatter does not expose a custom indent string to keep the UI minimal.
Is Minify safe on JSON that contains a long string with lots of spaces?
Yes. Minify only collapses whitespace that is outside string literals. The spec considers spaces, tabs, and newlines inside a quoted string to be part of the string value, so they are preserved byte-for-byte. Only the whitespace between tokens (before commas, after colons, around braces) disappears.
Why does minified JSON sometimes grow slightly after re-encoding?
Because <code>JSON.stringify</code> normalizes escapes. Source using <code>\u0041</code> for the letter A becomes a plain <code>A</code>, which shrinks. But raw Unicode characters above U+FFFF emit UTF-8 bytes that some transport layers count differently. Net size almost always drops; pre-escaped ASCII is the one case that can nudge slightly up.
Can I format a single primitive such as a number or a string?
Yes. RFC 8259 considers any JSON value a valid top-level document, including <code>42</code>, <code>"hello"</code>, <code>true</code>, <code>null</code>, or <code>[]</code>. Paste <code>"just a string"</code> with the surrounding quotes and Format will happily round-trip it. Older parsers (pre-RFC 7159) rejected bare primitives, but every modern browser accepts them.
More Developer Tools
Base64 Encoder & Decoder
Encode UTF-8 text to Base64 online or decode Base64 back to UTF-8 and plain text. Runs in your browser with no upload.
Open toolBulk URL Encode / Decode
Encode or decode many URLs at once. Paste a newline-separated list and the tool processes each line in parallel, preserving order and blank lines.
Open toolCode Screenshot
Create beautiful code snippet images with customizable themes.
Open toolColor Converter
Convert colors between HEX, RGB, HSL and CMYK formats.
Open toolCron Expression Parser
Parse cron expressions into human-readable schedules with next run times.
Open toolCSS Formatter / Minifier
Format, beautify and minify CSS code.
Open tool