How to Format and Validate JSON Online (Fix Every Parse Error)

2026-10-146 min readJSON Tools5 tools covered

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.

Key takeaways
  • 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".

Note

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

  1. Open the JSON formatter and validator and paste your JSON into the input pane.
  2. Press format. Valid JSON comes back indented; invalid JSON reports the position and the reason.
  3. 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.

Tip

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:

ErrorWhat it really meansBrokenFixed
Unexpected tokenJSON 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 inputA bracket or quote was never closed, typically lost while copying{"a": 1{"a": 1}
Unexpected token } in JSONA trailing comma — the last item is followed by ,{"a": 1, "b": 2,}{"a": 1, "b": 2}
Bad control characterA literal newline or tab sits inside a stringa raw line break inside quotesescape it as \n or \t
Unexpected token ' in JSON at position 0A BOM at the start of the file, or the content is not JSON at allan 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:

JSON
{
  "name": "Alice",
  "age": 30,
}

That produces Unexpected token } in JSON. Removing the comma after 30 is the whole fix:

JSON
{
  "name": "Alice",
  "age": 30
}

An unquoted key, which is the most common single cause of Unexpected token:

JSON
{ id: 1, "name": "Alice" }

Wrap the key in double quotes and it parses: { "id": 1, "name": "Alice" }.

Warning

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 doUseWhy
Re-indent and check syntaxJSON formatter and validatorThe default first step
Find a field deep in a nested structureJSON tree viewerCollapsible tree; far faster than scrolling once nesting runs dozens of levels deep
Put JSON in a URL or a config valueJSON minifier and escaperStrips whitespace to a single escaped line, and reverses it
Write YAML configJSON to YAML converterTwo-way conversion that preserves nesting and arrays
Generate code from an API responseJSON to class / entity generatorProduces 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.

Note

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

Related guides