JSON Formatter & Validator
Beautify, minify and validate JSON with exact error positions, auto-fix for common mistakes, a tree view and JSONPath search. Nothing is uploaded.
Pasting formats instantly. Ctrl/⌘+Enter formats from the keyboard.
Output
Formatted JSON appears here.
Why use this JSON formatter?
Most JSON formatters hand your text to JavaScript's JSON.parse, which rounds big numbers, gives Safari users no error position at all, and quietly drops duplicate keys. This one reads JSON with its own strict parser, so the output differs from your input only in whitespace, every error has an exact line and column in every browser, and anything risky is pointed out. It also repairs the near-JSON people paste every day, and everything happens on your device: API responses, tokens and config files are never uploaded.
How to format JSON online
- Paste JSON into the input, drop a file on it, or tap Upload. Pasting formats immediately.
- Press Format to beautify, Minify to compress, or Validate for a strict check. Pick 2 spaces, 4 spaces or tabs, and tick Sort keys if you want alphabetical order.
- If the JSON has errors, read the line, column and reason, press Jump to error, or let auto-fix repair the common mistakes.
- Switch to Tree to explore, search with text or JSONPath, then Copy or Download the result.
Common JSON errors and how to fix them
JSON is strict: keys and strings need double quotes, commas go only between items, and there are no comments. Each example below was run through this validator; the message is exactly what it reports. "Auto-fix" means Format and Minify repair it for you and list the change.
| Problem | Example | What the validator says | Auto-fix |
|---|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Trailing comma: remove the ',' before '}'line 1, column 17 | Yes |
| Single quotes | {'name': 'Ana'} | Property names must use double quotes ("), not single quotesline 1, column 2 | Yes |
| Unquoted key | {name: "Ana"} | Expected a property name in double quotes, found 'n'line 1, column 2 | Yes |
| Missing comma | {"a": 1 "b": 2} | Expected ',' or '}' after a property value, found '"' — is a comma missing?line 1, column 9 | Yes |
| Comment | {"debug": true // dev only
} | Comments are not allowed in JSON (auto-fix can remove them)line 1, column 16 | Yes |
| Python literal | {"ok": True} | True is Python, not JSON: write true (lowercase)line 1, column 8 | Yes |
| Unclosed bracket | {"items": [1, 2} | Expected ',' or ']' after an array item, found '}'line 1, column 16 | No: fix by hand |
| Line break in a string | {"note": "line one
line two"} | Unterminated string: a line break inside a string must be written as \nline 1, column 19 | No: fix by hand |
| NaN | {"ratio": NaN} | NaN and Infinity are not valid JSON numbers (use null, or a string)line 1, column 11 | No: fix by hand |
Unclosed brackets, doubled commas and NaN are left to you on purpose. A missing ] usually means the JSON was cut off when it was copied, and guessing where it ends would invent data. NaN and Infinity have no JSON equivalent: use null or a string, whichever the program reading the file expects.
What auto-fix repairs
Auto-fix reads text the way a forgiving JavaScript or Python reader would and writes strict JSON. It works token by token, so the inside of your strings is never rewritten: an apostrophe in "it's" stays an apostrophe. It handles:
- JavaScript object literals:
{name: 'Ana', tags: ['a', 'b',],}becomes{"name": "Ana", "tags": ["a", "b"]}. - Printed Python dicts: single quotes plus
True,FalseandNone. - JSON with comments (JSONC), such as
tsconfig.jsonand VS Code settings://,/* */and#comments are removed. - Copy-paste damage: curly quotes from a word processor or chat app, a byte-order mark, non-breaking spaces, a lone backslash in a Windows path.
- A missing comma between two values or properties, and a trailing comma before
}or]. - JSON Lines (one JSON value per line, as in log files and
.ndjsonexports): wrapped into one array.
Every fix is listed with its line number, so you can correct the source too. Validate never fixes silently: it reports the first real error and offers a Fix it button, with an Undo.
Searching JSON with JSONPath
JSONPath is a query language for picking values out of a JSON document, like a file path for data. $ is the root,.key or ['key'] steps into an object, [0] into an array, * matches everything at a level,.. searches at any depth, and [?( )] filters with comparisons on the current item @. These results come from running each query on the Sample JSON:
| Query | Selects | Result on the sample |
|---|---|---|
$.members[*].name | Every member's name | "Ana Ruiz", "Ben Okafor", "Chen Wei" |
$.members[-1].name | The last member's name (negative indexes count from the end) | "Chen Wei" |
$..id | Every id at any depth (.. searches recursively) | 101, 102, 103 |
$.members[0:2].role | Roles of members 0 and 1 (a slice, end excluded) | "lead", "engineer" |
$.members[?(@.active == false)].name | Names of members whose active flag is false | "Chen Wei" |
$.members[?(@.skills.length > 1)].name | Members with more than one skill | "Ana Ruiz", "Ben Okafor" |
$.budget['currency'] | Bracket notation, needed for keys with spaces or dashes | "EUR" |
Filters support == != < <= > >=, &&, ||, !, existence checks such as[?(@.manager)], regular expressions with =~ /pattern/i, and .length of arrays and strings. Type anything that doesn't start with $, . or [ to search keys and values as plain text instead.
Format, minify or validate?
| Action | Output | Use it for |
|---|---|---|
| Format | Indented, one value per line | Reading API responses, reviewing config, code reviews and diffs |
| Minify | One line, no spaces outside strings | Request bodies, environment variables, storage, smaller payloads |
| Validate | Your text, checked strictly | Finding the exact error before a deploy or an API call fails |
JSON, JSONC, JSON5 and JSON Lines
Plain JSON (RFC 8259) is what APIs send and what JSON.parse accepts. JSONC adds comments and is used by VS Code and TypeScript config files. JSON5 goes further, with single quotes, unquoted keys, trailing commas and hexadecimal numbers.JSON Lines (.jsonl, .ndjson) is one complete JSON value per line, common in logs and data exports. Validate checks plain JSON only; Format and Minify convert JSONC, most JSON5 and JSON Lines into plain JSON for you.
Big numbers, duplicate keys and other quiet problems
Valid JSON can still surprise the program that reads it. JavaScript stores every number as a 64-bit float, so an integer above 9,007,199,254,740,991 (253 − 1), like many database and social media IDs, is rounded by JSON.parse. This formatter keeps the exact digits and warns you, so you know to send such IDs as strings. Duplicate keys are legal but ambiguous, and most parsers keep only the last one; each duplicate is listed with both positions. Both warnings appear under the output.
Related tools
Turn an array of objects into a spreadsheet with the JSON to CSV converter, or go the other way with CSV to JSON. Checking a Kubernetes manifest or a CI file? TheYAML validator converts between YAML and JSON too. Read the claims inside a token with theJWT decoder, decode a Base64 payload with the Base64 decoder, compare two formatted versions with Text Diff (sort keys first for a cleaner diff), or flatten nested JSON into readable lines for an AI prompt with JSON/XML to text.
Frequently asked questions
How do I format JSON online?
Paste your JSON into the input box (or upload or drop a .json file) and press Format. The output appears indented with 2 spaces by default; choose 4 spaces or tabs from the Indent menu, then Copy or Download the result. Pasting formats automatically, and Ctrl+Enter (Cmd+Enter on a Mac) formats from the keyboard.
How do I check if my JSON is valid?
Press Validate. Valid JSON gets a green confirmation with its key count and depth. Invalid JSON shows the exact line and column where it stops being JSON, a plain-English reason such as a missing comma or a trailing comma, and the offending line with a caret under the problem. Jump to error puts the cursor on that spot in the input.
Why does my JSON say 'Unexpected token'?
That is the generic message JavaScript's JSON.parse gives for any character it didn't expect. The usual causes are a trailing comma before } or ], single quotes instead of double quotes, an unquoted property name, a comment, or a missing comma between two values. Paste the JSON here and the validator names the specific cause and its line and column, in every browser including Safari, which gives no position at all.
Can it fix invalid JSON automatically?
Yes, for the common mistakes: trailing commas, single-quoted strings, unquoted keys, comments (as in tsconfig.json or VS Code settings), Python's True/False/None, curly quotes from a word processor, a missing comma between values, and several JSON Lines values that need wrapping in an array. Format and Minify apply the fixes and list each one with its line number; Validate reports the error and offers a Fix button. Unclosed brackets, doubled commas and NaN are never guessed at.
Does this tool send my JSON to a server?
No. Formatting, validation, the tree view and search all run in your browser with JavaScript, and nothing is uploaded or logged. To survive a page change, your current input is kept in this tab's session storage, which the browser clears when you close the tab, and your settings (indent, sort keys, view) are remembered on this device.
Will formatting change my numbers?
No. Formatting and minifying only change whitespace (and key order, if you tick Sort keys). Every number keeps its exact text, so a 64-bit ID like 12345678901234567890, a price like 1.10 or an exponent like 1e2 comes out as written. Many formatters round-trip through JSON.parse, which rounds integers above 9,007,199,254,740,991; when your JSON has such numbers, the tool also warns you, because any JavaScript app reading the file will round them.
How do I search JSON with JSONPath?
Type a path starting with $ into the search box under the output, for example $.members[*].name for every member's name, $..id for every id at any depth, or $.members[?(@.active == true)] to filter. Matches are listed with their full paths and you can copy them all as a JSON array. Anything that doesn't start with $, . or [ is treated as plain text and matched against keys and values.
What does the tree view do?
Tree view shows the JSON as collapsible objects and arrays with their sizes, so you can explore a large response without scrolling through thousands of lines. Selecting any row shows its JSONPath, which you can copy along with the value. Large arrays are shown in pages of 200 items so the page stays fast.
Can I sort JSON keys alphabetically?
Yes. Tick Sort keys before Format or Minify and every object's keys are put in alphabetical (Unicode code point) order at every level, the same order as jq -S or Python's sort_keys. Arrays keep their order, because order is part of an array's meaning. Sorting is handy before comparing two JSON files in a diff tool.
Does it detect duplicate keys?
Yes. JSON technically allows the same key twice in one object, but parsers disagree about what it means and most silently keep only the last value. The formatter warns about every duplicate with the line and column of both occurrences, and keeps both in the output so nothing disappears without you knowing.
Can I format large JSON files?
Yes. The formatter is a single pass over the text, so a 10 MB file formats in a second or two on a laptop, and drag-and-drop or Upload avoids pasting huge text. To keep the page responsive, syntax colouring switches off above about 400 KB and only the first 1 MB of a bigger result is displayed; Copy and Download always include all of it. Extremely deep nesting (thousands of levels) can still be minified and validated, but not pretty-printed, because the indentation alone would run to gigabytes.
What's the difference between formatting and minifying JSON?
Formatting (also called beautifying or pretty-printing) adds line breaks and indentation so people can read the structure. Minifying removes every space and line break that isn't inside a string, giving the smallest valid JSON for APIs, config payloads and storage. Both produce exactly the same data.
Related tools
More free, private, browser-based utilities — no upload, no sign-up.