Local-first tools. Your files and text stay in your browser.

data guide

JSON formatting and validation: a practical guide

Understand why JSON fails to parse, how to read line and column errors, and what formatting and minifying actually change.

Reviewed December 1, 2026 · TinkerFern editorial

JSON looks simple until a trailing comma or an unquoted key breaks a build. This guide covers the rules that actually cause failures, how to read parser errors, and when formatting or minifying is useful.

The strict grammar

JSON is a data interchange format, not JavaScript. Several conveniences that are valid in JavaScript objects are invalid JSON:

  • Trailing commas: {"a": 1,}
  • Comments: // note or /* note */
  • Unquoted keys: {a: 1}
  • Single-quoted strings: {'a': 1}
  • undefined, NaN and Infinity
  • Functions or expressions

If a payload contains any of these, a strict parser rejects the whole document. That strictness is the point: every JSON parser in every language agrees on what the document means.

Reading a parse error

Modern parsers report a position. A message like “Unexpected token } in JSON at position 42” tells you where parsing stopped, not necessarily where the mistake began. The real cause is often just before that position: a missing comma, an extra comma, or an unclosed quote.

A reliable workflow:

  1. Jump to the reported line.
  2. Look at the token before the error position.
  3. Check the matching brackets and quotes around it.
  4. Fix one error and re-run; parsers usually stop at the first problem.

Formatting versus minifying

Formatting adds indentation and line breaks. It does not change values, key order or types. It makes diffs readable and review possible.

Minifying removes insignificant whitespace. It makes the payload smaller for transport, but it also makes review harder. A sensible rule is to format while working and minify only for delivery, keeping the original somewhere version-controlled.

Neither operation should reorder object keys. If you need stable ordering for hashing or signing, sort keys explicitly with a dedicated tool or in code.

Duplicate keys

The JSON specification does not give duplicate keys a meaningful interpretation. Most parsers keep the last value. That means a document with {"a": 1, "a": 2} may be accepted and silently become {"a": 2}. If exact duplication matters, detect it before parsing with a linter.

Encoding and Unicode

JSON is Unicode text, normally encoded as UTF-8. Escapes such as \u00e9 and literal é are equivalent. When a formatter re-serializes a document, it may choose one representation; the parsed value is the same.

Watch out for:

  • Byte order marks at the start of a file, which some parsers reject.
  • Smart quotes pasted from word processors.
  • Invisible characters introduced by copy/paste.

Size and performance

Very large JSON files are better handled with streaming parsers than with a browser text area. For everyday configuration files and API responses under a megabyte, a local formatter is faster than round-tripping through a server and avoids sending potentially sensitive payloads anywhere.

Paste your document into the JSON formatter to validate it, or use the text toolkit if the problem is whitespace rather than syntax.

Tools mentioned in this guide

Apply the advice with a tool that runs locally.

← All guides