What a JSON formatter actually does
This page runs your text through the browser built-in JSON.parse() and prints the result back with JSON.stringify(), so it is not guessing at your document with a regular expression. Either the text is valid JSON and you get an indented copy of exactly the data a real parser saw, or it is not and you get the parser error, at the position where it gave up. Formatting and validating are the same operation here.
JSON is far stricter than the JavaScript or Python it looks like. The grammar, fixed in RFC 8259 and ECMA-404, allows exactly six kinds of value: object, array, string, number, the literals true and false, and null. Strings must use double quotes, keys are strings and therefore quoted too, there are no comments, no trailing commas, no single quotes, no hexadecimal, and no NaN or Infinity. A document that your editor highlights happily can still be rejected by every server you send it to.
Whitespace between tokens carries no meaning in JSON, so formatting and minifying are two views of one document.
Formatted, minified or tree: which output you want
- Format with 2 spaces: the default, and the convention most web tooling emits. Use it for anything that will end up in a repository, since a file that matches what npm, Prettier and your teammates produce keeps diffs small.
- Format with 4 spaces: the house style in plenty of backend and mobile codebases, and easier to follow when the nesting is deep. Match the file you are pasting into rather than your own taste.
- Minify: strips every insignificant space and newline. Use it when the JSON has to travel as one line: a shell argument, an environment variable, a database column, or a config field that accepts only a single line.
- Tree view: for reading rather than producing. Every value carries a type badge, so you can see at a glance that the field you expected to be a number arrived as a string, and containers show how many children they hold. Clicking a key copies its JSONPath.
- Validation only: press Format and look for the red box. No error means the document parsed cleanly.
How to read an API response you just captured
- Copy the response body. In Chrome or Firefox DevTools that means the Network panel: select the request, open the Response tab and copy the raw text.
- Paste it into the box above and press Format. If a red box appears, you probably copied the headers along with the body, or the endpoint returned an HTML error page rather than JSON.
- Switch to Tree view and collapse the branches you do not care about. The type badges are the fastest way to spot the usual API surprises: an ID sent as a string, a boolean sent as
"false", an empty list that arrived asnull. - Click the key you need. The JSONPath lands on your clipboard, ready for jq, a test assertion or a line of code that has to walk to that field.
How to fix JSON that refuses to parse
Read the line and column in the error box, where the character the parser stopped on is marked in red, press Select the error in the input to put your cursor there, then look at the few characters before it. Parsers report where they noticed the problem, not where you made it. These are the offenders, in rough order of how often they show up:
- Trailing comma:
{"a": 1, "b": 2,}is fine in modern JavaScript and invalid in JSON. Delete the last comma. - Single quotes or unquoted keys:
{a: 'x'}is a JavaScript object literal, not JSON. It has to be{"a": "x"}. - Comments: remove every
//and/* */. If the file is meant to keep them, it is JSONC or JSON5, not JSON. - Curly quotes: text that passed through a word processor, a chat app or a slide deck often comes back with
“and”in place of". Retype the quotes. - Unescaped characters inside strings: a literal double quote has to be
\", a newline\n, a backslash\\. A Windows path pasted in raw is the classic case. - An invisible first character: a byte order mark left by a Windows editor sits before the opening brace and makes the parser fail at position 0. Delete everything ahead of the
{and paste again. - Python or log output rather than JSON:
True,Noneand'single quotes'mean you copied the printed form of a dict. Print it withjson.dumps()instead.
Getting the result where it needs to go
The Copy button above the result copies the whole formatted document; in the tree view, clicking a key copies only its path.
- Into an editor: paste the formatted version, not the minified one. Your reviewer reads the diff, and a file that is one very long line shows up as a single changed line no matter how small the edit was.
- Into a shell: minify first, then wrap the whole thing in single quotes so the shell leaves the double quotes alone, as in
curl -d '{"id":1}' -H 'Content-Type: application/json'. On Windows PowerShell the quoting rules differ, so a here-string or a file is safer than an inline literal. - Into an environment variable or a single-line config: minify, and remember that a JSON value containing a newline can only be stored as
\ninside a string. - Sharing with someone else: strip tokens, keys and personal data first. What you paste here stays in your browser, but what you forward afterwards does not.
The same document in other languages and stores
Every runtime has its own formatter, and they do not all agree on what they will accept or emit.
- JavaScript and TypeScript:
JSON.stringify(value, null, 2)is what this page does. Pass a string as the third argument for tabs, as inJSON.stringify(value, null, '\t'). A numeric indent above 10 is clamped to 10 by the specification. - Python:
json.dumps(obj, indent=2), orpython -m json.tool file.jsonfrom a terminal. Two defaults catch people out:ensure_asciiescapes non-ASCII text to\uXXXXunless you passensure_ascii=False, and the module accepts and emitsNaNandInfinity, neither of which exists in JSON. Passallow_nan=Falsefor portable output. - Command line:
jq .pretty-prints andjq -c .compacts, both streaming, which is how to handle a file too large for a browser tab. - PostgreSQL: the
jsontype keeps your exact text, including whitespace, key order and duplicate keys. Thejsonbtype parses into a binary form, so whitespace disappears, key order is not preserved and duplicate keys are collapsed.jsonb_pretty()gives you an indented rendering back. Pickjsonbunless you genuinely need the original bytes. - Log pipelines: a file with one JSON document per line, often called JSON Lines or NDJSON, is not a single JSON document and will not parse here as a whole. Paste one line at a time.
- Editors: VS Code accepts comments and trailing commas in
tsconfig.jsonand its own settings files because it treats them as JSONC. That tolerance does not extend topackage.json, which npm parses strictly.
Limits and privacy
What leaves your browser: nothing. Parsing and printing both happen on your device through the browser JSON functions. The text you paste is not sent anywhere, not logged and not stored on a server, and the page keeps no copy once you close the tab. Session recording on this site is configured to mask this tool, so the pasted document is not captured there either.
Numbers are the one place data can change. A JavaScript parser turns every JSON number into a double, so integers beyond 9007199254740991 are rounded and long decimal values can come back with a different tail. If your payload carries large IDs or money amounts, read them from the raw text and have the producer send them as strings.
Two more things a round trip can quietly alter. Duplicate keys collapse to the last occurrence, which RFC 8259 warns is parser-dependent, and keys that look like non-negative integers are reordered ahead of the rest because that is how JavaScript objects enumerate. When either detail matters, treat the output as a view rather than a replacement for the original file.
Size. Everything runs in one browser tab, so a very large document can freeze it, and the tree view is the heavier mode because it builds a node per value. Reach for a streaming tool past a few megabytes.
This is syntax checking, not schema validation. A document can be perfectly valid JSON and still be wrong for the API you are sending it to. For required fields, types and allowed values, you need a JSON Schema validator or the documentation for the service itself.
Frequently asked questions
Why does my JSON fail to parse when it looks correct?
Almost always one of five things: a trailing comma before a closing brace or bracket, single quotes instead of double quotes, keys written without quotes, a // or /* */ comment, or curly quotes pasted in from a word processor or a chat app. All five are legal in JavaScript source or in a Python dict, and none of them are legal JSON. The red box under the input shows the message from your browser plus the line and column, worked out on this page so every browser gets them, and lists the failing line with its neighbors and the character where the parser stopped marked in red. Select the error in the input puts your cursor on it. Start reading there and work backwards a line or two, because the real mistake is usually just before the point where the parser gave up.
What is the difference between formatting and minifying?
Nothing but whitespace. Formatting adds newlines and indentation so a human can follow the nesting; minifying strips every space and newline between tokens so the payload is as small as possible. The parsed data is identical either way, which is why you can round-trip a document through both buttons and get back exactly what you started with. Send minified JSON over the wire and read formatted JSON on screen.
Is my JSON uploaded to a server?
No. The page calls the browser built-in JSON.parse and JSON.stringify on your own device, and the text you paste never leaves the tab. There is no request carrying your input, no logging of it, and nothing is kept after you close the page. That makes it safe to paste an API response that contains tokens or customer records, although it is still worth redacting anything you do not need before you paste.
Should I indent with 2 spaces or 4?
Two spaces is the common default for JSON in web projects and is what most formatters emit, including this page and the JSON that npm writes into package.json. Some teams standardize on four spaces across every file type. Pick whichever matches the repository you are pasting into, because a diff full of reindented lines hides the change you actually made.
Why did my long ID number change after formatting?
JavaScript parses every JSON number into a 64-bit floating point double, which holds integers exactly only up to 9007199254740991. A 19-digit snowflake ID or a bigint primary key is past that limit, so it is rounded on the way in and the rounded value is what gets printed back out. The fix is on the producing side: serialize large identifiers as JSON strings. If you only need to read the value, search the raw text rather than trusting the formatted output.
What happens if the same key appears twice in one object?
RFC 8259 says names within an object should be unique but does not forbid duplicates, and it warns that behavior with duplicate names is unpredictable across parsers. JSON.parse in the browser keeps the last occurrence and silently discards the earlier ones, so the formatted output will show only one of them. If you are debugging a payload where a value seems to vanish, search the raw text for the key before you assume the server never sent it.
Does formatting reorder my keys?
Usually no: ordinary string keys come back out in the order they appeared. The exception is keys that look like non-negative integers, such as "2" and "10". JavaScript objects always list integer-like keys first and in ascending numeric order, so a map keyed by ID will come back sorted rather than in the original order. The data is the same, but if key order matters to you, treat the raw text as the source of truth.
Can I put comments in a JSON file?
Not in JSON itself. The grammar has no comment syntax, so a // or /* */ line makes the document invalid and package.json or a strict API will reject it. Two supersets exist for the cases where humans edit the file by hand: JSONC, which adds comments and is what VS Code accepts in tsconfig.json and its own settings, and JSON5, which adds comments, trailing commas, unquoted keys and single quotes. Strip both back to plain JSON before sending anything over an API.
How do I get the path to a nested field?
Switch to the tree view and click the key you want. The page copies a JSONPath-style string such as $.data.items[0].id, built from the position of that node in the document. Bracket notation is used for array indices and for keys that are not plain identifiers, so a key with a space or a dash comes out as ["user-id"] rather than breaking the path. Paste that into jq, a JSONPath query or your own code.
How large a document can this handle?
It is limited by the memory of your browser tab rather than by any fixed cap, and the practical ceiling depends on your device. A few megabytes formats without trouble on a laptop; tens of megabytes can lock the tab up while it renders, and the tree view is heavier than the text view because it creates a DOM node per value. For log files and database dumps, a streaming command line tool such as jq is the better answer.
Sources
- IETF, RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format (the grammar, UTF-8 as the interchange encoding, and the warning about duplicate object names).
- MDN, JSON.parse() and JSON.stringify() (the two functions this page calls, including the indent argument and its limit of 10).
- json.org (Douglas Crockford’s one-page railroad diagrams of the grammar, and the companion standard ECMA-404).
- Behavior of the
jsonandjsonbcolumn types, of the Pythonjsonmodule, and of JSONC in VS Code is described in each project’s own documentation, which can change between versions.
More developer tools
If a field holds an opaque blob, try it in the Base64 decoder; three dot-separated segments usually mean a JWT, whose header and payload are themselves JSON. Query strings that carry escaped JSON are easier to read after a pass through the URL encoder and decoder, and when you need an identifier for a new record the UUID generator produces one that will not collide.
Related tools
- Base64 Encode and Decode
Base64 encode and decode with full UTF-8 support, so accented letters, CJK and emoji survive the round trip.
- JWT Decoder
JWT decoder for the header, payload, issuer, algorithm and expiry of any JSON Web Token, i…
- URL Encoder and Decoder
URL encoder and decoder with encodeURI and encodeURIComponent modes: decode a garbled URL …
- UUID Generator (v4 and v7)
UUID generator for v4 (random) and v7 (time-ordered) identifiers in bulk, with one-click c…
- Word Counter & Character Count
Word counter and character count as you type, with and without spaces, sentences and paragraphs.
Privacy: your JSON is parsed and printed by your own browser with JSON.parse() and JSON.stringify(). It is never uploaded, never logged and never stored on a server, and the tool is masked from session recording. Analytics sees only that this page was viewed, never its contents.
