How to Format and Validate JSON Online (Fix Every Parse Error)
JSON copied out of a log, an API response or a database column usually arrives on a single line with the indentation flattened. Formatting it does two jobs at once: a parser confirms the structure is legal, and you get to see the hierarchy.
- Formatting and validating are the same operation - the tool must parse the whole document to re-indent it, so a clean format means valid syntax
- Formatting only changes whitespace; keys, values, numeric precision and array order are untouched
- When the reported error position is line 1, column 1, the content is usually not JSON at all - often an HTML error page
- Unquoted keys are the single most common cause of "Unexpected token"
- All parsing runs in your browser; nothing you paste is uploaded
#Format first, edit second
JSON that comes from a log file, an API response or a database column tends to arrive in one of three states: collapsed onto a single line, indented inconsistently, or escaped inside another string.
Editing data in any of those states is how you end up deleting a bracket or losing a comma — after which nothing parses, and the error message only tells you there is "an unexpected character on line 1".
Formatting splits the job in two: the parser confirms the structure is valid, then you read the hierarchy. The few seconds spent here usually save a much longer debugging session later.
#Three steps to format and validate
- Open the JSON formatter and validator and paste your JSON into the input pane.
- Press format. Valid JSON comes back indented; invalid JSON reports the position and the reason.
- Copy the result back into your code or config file.
Formatting and validating are the same operation. To re-indent the text, the tool has to parse the whole document against the JSON grammar first. If parsing succeeds, the syntax is valid; if it fails, you have a syntax error.
There is no need to validate and then format separately — one action answers both questions.
The input pane accepts a dragged .json file, so a few hundred kilobytes of config or response data never has to be copied by hand.
#What each parse error actually means
The error keywords are a small, fixed set. This table pairs the message you see with the real cause and the fix:
| Error | What it really means | Broken | Fixed |
|---|---|---|---|
Unexpected token | JSON does not allow whatever appeared here. Usually an unquoted key, single quotes, or something that only exists in JavaScript — comments, functions, undefined | {name: 'Tom'} | {"name": "Tom"} |
Unexpected end of input | A bracket or quote was never closed, typically lost while copying | {"a": 1 | {"a": 1} |
Unexpected token } in JSON | A trailing comma — the last item is followed by , | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
Bad control character | A literal newline or tab sits inside a string | a raw line break inside quotes | escape it as \n or \t |
Unexpected token ' in JSON at position 0 | A BOM at the start of the file, or the content is not JSON at all | an invisible byte before { | save as UTF-8 without BOM |
Now the two you will actually hit, side by side with the fix.
A trailing comma, which is legal in JavaScript and several other languages but not in JSON:
{
"name": "Alice",
"age": 30,
}That produces Unexpected token } in JSON. Removing the comma after 30 is the whole fix:
{
"name": "Alice",
"age": 30
}An unquoted key, which is the most common single cause of Unexpected token:
{ id: 1, "name": "Alice" }Wrap the key in double quotes and it parses: { "id": 1, "name": "Alice" }.
When the reported position is "line 1, column 1", the problem is almost never the syntax itself — it is that the content is not JSON. An API that returned an HTML error page, or a YAML file treated as JSON, produces exactly this.
#Which JSON tool to reach for
There is more than one JSON tool on this site, and picking by intent saves time:
| What you want to do | Use | Why |
|---|---|---|
| Re-indent and check syntax | JSON formatter and validator | The default first step |
| Find a field deep in a nested structure | JSON tree viewer | Collapsible tree; far faster than scrolling once nesting runs dozens of levels deep |
| Put JSON in a URL or a config value | JSON minifier and escaper | Strips whitespace to a single escaped line, and reverses it |
| Write YAML config | JSON to YAML converter | Two-way conversion that preserves nesting and arrays |
| Generate code from an API response | JSON to class / entity generator | Produces Java, TypeScript or Go definitions in one pass |
The distinction is simple: to understand a structure, use the formatter or the tree view; to change the format, use a converter.
#Three habits worth adopting
#Format before you search
Searching for a field name inside collapsed JSON returns a flat list of hits. Once the document is formatted — one key per line — every result carries its indentation with it, so the parent it belongs to is immediately visible. When a field name repeats many times, the difference is dramatic.
#Do not re-format a large file repeatedly
Anything past a few hundred kilobytes is re-parsed in full on every format. If you are changing one or two fields, format once at the end rather than toggling back and forth. If you genuinely need to explore the structure repeatedly, the tree viewer is the better tool.
#Check the encoding when text looks wrong
Mojibake is usually an encoding problem, not a JSON problem. Confirm the source is UTF-8 and carries no BOM. The JSON specification requires UTF-8, and characters from other encodings can display incorrectly even when the syntax is valid.
A typical encoding failure looks like this: the JSON is valid and formats cleanly, but every non-ASCII character turns into something like é. That is almost always the file having been saved as Latin-1 or GBK.
#Frequently asked questions
#Does formatting JSON online upload my data?
No. Every part of the parsing and formatting happens inside your own browser; what you paste is never sent to a server, and it disappears when you close the page. You can confirm this yourself with the network panel in your browser's developer tools — formatting issues no requests at all. This is how every tool on this site works, with the single exception of the online code runners.
#Does formatting change the data?
No. Formatting only adjusts whitespace — indentation, line breaks and spaces. Keys, values, numeric precision and array order are all untouched. That is why the result is safe to paste back into code: the parsed object is exactly equivalent to the original.
#How large a file can it handle?
Files up to a few megabytes generally work in a browser; the practical ceiling depends on your machine's memory. Larger files get sluggish, and past roughly ten megabytes a command-line tool is the better choice. Day-to-day API responses and config files sit comfortably under a few hundred kilobytes.
#What is the difference between JSON and a JavaScript object?
JSON is a data interchange format; a JavaScript object is a data type in a programming language. They look alike but follow different rules. JSON requires double-quoted keys and forbids comments, functions, undefined and trailing commas — all of which a JavaScript object permits. That is why pasting an object literal from source code into a JSON parser so often fails with Unexpected token. The reverse direction is safe: valid JSON is always a valid JavaScript object literal.
#Can numbers lose precision?
Large integers can. The JSON specification does not cap number length, but JavaScript represents numbers internally as double-precision floats, so integers beyond 2^53 may be rewritten during parsing. If your data contains long integer IDs — a 19-digit snowflake ID, for instance — check the trailing digits after formatting. Such fields are usually better transmitted as strings.
Tools used in this guide
Format, validate and minify JSON. Syntax errors are reported with the exact l…
Open tool →JSON ViewerTree view JSON explorer with collapsible nodes
Open tool →JSON Minify & EscapeRemove whitespace, escape strings, unescape support
Open tool →JSON to YAMLBidirectional conversion with nested arrays support
Open tool →JSON to ClassGenerate Java / TS / Go classes from JSON
Open tool →