JSON explained: format, validate, and fix common errors

6 min readUpdated May 24, 2026

JSON (JavaScript Object Notation) is the lingua franca of web APIs and config files. It is simple — but a single trailing comma or smart quote can break a whole payload. This guide covers the rules, the tooling, and the errors you will actually hit.

What JSON is (and is not)

JSON is a text format for structured data built from two structures: objects ({ "key": value }) and arrays ([ value, value ]). Values can be a string, number, boolean, null, object, or array — nothing else.

Crucially, JSON is *not* JavaScript. It has no comments, no functions, no undefined, no trailing commas, and keys must be double-quoted strings.

{
  "name": "ada",
  "active": true,
  "roles": ["admin", "dev"],
  "meta": null
}

The 5 rules that trip people up

  • Double quotes only. 'single' quotes are invalid. So are unquoted keys.
  • No trailing commas. [1, 2, 3,] is valid JavaScript but invalid JSON.
  • No comments. // like this will fail. Strip them before parsing.
  • Numbers are plain. No leading zeros, no NaN, no Infinity.
  • Escape special characters in strings: \n, \t, \", and \\.

How to format and validate JSON

Formatting (or "beautifying") adds consistent indentation so nested data is readable; validating confirms the document actually parses. Both happen in one step when you paste into the JSON Formatter — it runs entirely in your browser, so even secrets stay local.

Programmatically, the browser and Node give you this for free:

const obj = JSON.parse(raw)            // validate + parse
const pretty = JSON.stringify(obj, null, 2) // format with 2-space indent
const min = JSON.stringify(obj)        // minify

Common parse errors and their fixes

"Unexpected token } in JSON"

Almost always a trailing comma before the closing brace or bracket. Remove it.

"Unexpected token ' in JSON"

You used single quotes. Replace every ' around keys and string values with ".

"Unexpected end of JSON input"

The document is truncated — a brace or bracket is unclosed. Format the JSON and the editor will show where nesting breaks.

Pasting an API response that looks fine but won’t parse? It may be double-encoded (a JSON string *inside* a JSON string). Decode once, then parse again.

Converting JSON to other formats

Once your JSON is valid, converting is trivial. Turn it into YAML for config files with the JSON ↔ YAML converter, into a spreadsheet with JSON ↔ CSV, or into XML for legacy systems.

Frequently asked questions

Is it safe to paste sensitive JSON into an online formatter?
With ilovedev, yes — formatting runs entirely in your browser via JSON.parse/stringify. Nothing is uploaded. Avoid tools that POST your data to a server.
Why does valid-looking JSON fail to parse?
The usual suspects are trailing commas, single quotes, comments, or unquoted keys. The parser error points to the exact character; formatting the input makes the problem obvious.
What is the difference between formatting and minifying?
Formatting adds indentation and newlines for readability. Minifying strips all whitespace to shrink the payload — useful for production API responses.
Can JSON have comments?
No. The spec forbids them. Some supersets (JSON5, JSONC) allow comments, but standard JSON.parse will reject them.

Try it yourself

Put this guide into practice — these tools run free in your browser.