JSON Formatter & Minifier

Beautify or minify JSON data. Validates syntax automatically.

Input

Output

Result will appear here...

JSON formatting, validation and the errors behind them

JSON (JavaScript Object Notation) is defined by RFC 8259 and ECMA-404, and it is smaller than most people assume. There are exactly six kinds of value: objects, arrays, strings, numbers, the literals true and false, and null. Strings must use double quotes. Numbers may not have leading zeros, a hex prefix, or the values NaN and Infinity. Comments do not exist in the grammar. Any value, not only an object or array, may appear at the top level. Almost every "my JSON will not parse" problem is a violation of one of those rules.

What this formatter does

The page parses your text with the browser's native JSON.parse about half a second after you stop typing, then re-serialises it with JSON.stringify: two-space indentation in Format mode, or no whitespace at all in Minify mode. If parsing fails, the output panel shows the parser's own error message, which points at the first character it could not accept, and the formatted view returns as soon as the text parses again. Nothing is uploaded; the text stays in the page.

Because the output is a fresh serialisation rather than a whitespace edit, a few things are normalised on the way through. Knowing them saves confusion when you diff the result against the original:

  • Integer-like keys move first. JavaScript orders own properties with keys such as "2" ahead of other keys, so {"b":1,"2":2,"a":3} comes back as {"2":2,"b":1,"a":3}. Other keys keep their original order.
  • Large integers lose precision. JavaScript numbers are IEEE 754 doubles, exact only up to 2^53 - 1 (9007199254740991). A 64-bit ID such as 12345678901234567890 is re-printed as 12345678901234567000. APIs work around this by sending IDs as strings (Twitter's id_str is the classic example).
  • Duplicate keys collapse. JSON.parse keeps the last occurrence, so {"a":1,"a":2} becomes {"a":2} with no warning.
  • Number spelling is canonicalised. 1.0 prints as 1, 1E2 as 100, -0 as 0, and a literal outside double range such as 1e400 parses to Infinity and serialises as null.
  • Escapes are rewritten. é comes back as the character é, and unnecessary escapes like \/ are dropped. The meaning is identical.

Errors you will see, and what they mean

Input problemWhy it failsFix
Trailing comma: {"a":1,}Commas only separate members; a comma before } or ] is illegal.Delete the last comma.
Single quotes: {'a':1}Only double-quoted strings exist in JSON.Replace with double quotes; this is JavaScript object syntax, not JSON.
Unquoted keys: {a:1}Keys are strings and need quotes.Write {"a":1}.
Comments: // note or /* */The grammar has no comment token.Remove them, or treat the file as JSONC and strip comments before parsing.
NaN, Infinity, undefinedNot JSON values.Use null or a string.
True, NonePython spellings; JSON is lowercase true and null.Serialise with json.dumps instead of str().
Several objects one after anotherOnly one top-level value is allowed. Log files often use NDJSON, one document per line.Paste a single line, or wrap the lines in [ ] with commas.
Error at position 0 with nothing visibly wrongAn invisible byte order mark (U+FEFF) from a Windows editor, or curly "smart quotes" pasted from a document.Re-save as UTF-8 without BOM; replace curly quotes with straight ones.
Raw line break inside a stringControl characters must be escaped inside strings.Use \n.

JSON, JSONC, JSON5 and NDJSON

Several near-JSON dialects are common in developer tooling. JSONC (JSON with comments) is what VS Code uses for settings.json, and TypeScript accepts comments and trailing commas in tsconfig.json. JSON5 goes further with single quotes, unquoted keys, hex numbers and multi-line strings. NDJSON, also called JSON Lines, stores one complete JSON document per line and is the usual shape of structured logs and bulk export files. This formatter is strict RFC 8259: it will reject all three, which is useful when you need to know whether a file is portable to a parser that is not as forgiving as your editor.

Command-line equivalents

jq . data.json                    # pretty-print (jq -c for minify, jq -S to sort keys)
jq empty data.json                # validate only; exit code 0 means well-formed
python3 -m json.tool data.json    # pretty-print with 4 spaces
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), separators=(',',':')))" < data.json
node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(0,'utf8')),null,2))" < data.json
Get-Content data.json | ConvertFrom-Json | ConvertTo-Json -Depth 100   # PowerShell

Safety notes

JSON.parse never executes code, unlike the eval trick from the early 2000s, so parsing untrusted JSON is safe in itself. The risks appear afterwards: naive deep-merge helpers that copy a parsed "__proto__" key into another object can pollute prototypes, and deeply nested or very large documents can exhaust memory in a recursive handler. Validate structure with a schema (JSON Schema, Zod, pydantic) before trusting the shape.

Client-side, with one honest caveat

Parsing runs entirely in your browser and the page has no upload endpoint. Browser extensions that are allowed to read page content can still see what you paste, so avoid pasting live credentials into any web page, including this one. The JSON Diff and YAML to JSON tools work the same way.

How to use

  1. Paste raw, minified or hand-edited JSON into the Input panel. Parsing runs automatically about half a second after you stop typing.
  2. Choose Format for two-space indentation, or Minify to strip every byte of whitespace.
  3. If the panel reports Invalid JSON, read the position in the message; the first illegal character is usually a trailing comma, a single quote or a comment.
  4. Click Copy to place the result on your clipboard, or Clear to start over.

Common use cases

  • Beautifying a minified API response copied from the browser Network tab while debugging.
  • Checking that a hand-edited config file (package.json, .eslintrc, a Kubernetes manifest converted from YAML) is still valid before committing.
  • Minifying a payload that has to fit in an environment variable, a query parameter or a size-limited message.
  • Spotting 64-bit IDs that need to be strings before a JavaScript client silently rounds them.
  • Normalising two exports to the same indentation before comparing them in the JSON Diff tool.
  • Confirming whether a file is strict JSON or a JSONC file that only your editor tolerates.

Frequently asked questions

Is the JSON I paste sent to your servers?

No. Parsing, validation and pretty-printing use the browser's built-in JSON.parse and JSON.stringify functions and nothing is uploaded. The one thing a web page cannot promise is privacy from browser extensions that have permission to read page content, so keep live secrets out of any online tool.

What is the difference between Format and Minify?

Format inserts newlines and two-space indentation so a person can read the structure. Minify removes all optional whitespace so the document is as small as possible for transmission or storage. Both produce the same parsed value; only the whitespace differs.

Why does my JSON fail to parse when it looks fine?

The usual causes are a trailing comma before a closing bracket, single quotes instead of double quotes, comments, unquoted keys, or Python spellings such as True and None. An error at position 0 with nothing visible usually means an invisible byte order mark or curly quotes pasted from a word processor.

Does this support JSON5 or JSONC (comments and trailing commas)?

No. The formatter is strict RFC 8259 on purpose, so it tells you whether a file will work in parsers that are less forgiving than VS Code or the TypeScript compiler. Strip comments and trailing commas first if you need to check a JSONC file.

Why did a long number change after formatting?

JavaScript stores numbers as 64-bit floating point, which is exact only up to 9007199254740991 (2^53 - 1). Larger integers such as database or Snowflake IDs are rounded when parsed. Send such values as strings in your API, which is why many services offer an id_str field.

Why did the order of my keys change?

JavaScript places keys that look like non-negative integers (for example "1" or "42") first, in numeric order, before all other keys. Everything else keeps its original order. JSON itself defines objects as unordered, so no correct consumer should depend on key order.

Does it handle Unicode, emoji and Indian-language text?

Yes. Strings are Unicode by definition and the formatter outputs characters such as é, Devanagari text or emoji directly rather than as \u escapes. If you need pure ASCII output for an old system, use jq -a or Python json.dumps with ensure_ascii=True.

Can it sort keys alphabetically?

Not in the browser tool, which preserves the original order. On the command line, jq -S . file.json or python3 -c with json.dumps(obj, sort_keys=True) will sort keys recursively, which is handy before diffing two documents.

Advertisement