JSON fundamentals

How to format and validate JSON correctly

Learn a reliable workflow for making JSON readable while confirming that the document remains valid strict JSON.

10 min read Reviewed July 19, 2026 Professional reference

Document summary

A practical guide to indentation, syntax validation, key order, parser errors, and safe output review.

Key takeaways

  • Use strict, representative input before relying on output.
  • Review structure, types, and edge cases instead of checking only visual formatting.
  • Continue examples inside the connected Bacodev tool to verify the result.
01

Formatting and validation solve different problems

Formatting changes whitespace and indentation. Validation checks whether the structure follows strict JSON grammar.

A document can look readable and still be invalid because of a trailing comma, comment, single quote, or unescaped character.

02

Use a repeatable validation workflow

  1. 1

    Keep a copy of the original input.

  2. 2

    Parse the input before applying formatting.

  3. 3

    Read the first error location and inspect the surrounding characters.

  4. 4

    Format only after the parser accepts the document.

  5. 5

    Compare important values before replacing the source file.

03

Remember what strict JSON permits

ElementValid JSONCommon mistake
Property namesDouble quotedBare or single quoted names
CommasBetween values onlyTrailing comma
Special valuestrue, false, nullundefined, NaN, Infinity
CommentsNot supported// or block comments
04

Compare invalid and valid structure

Invalid
{
  name: 'Report',
  active: true,
}
Valid
{
  "name": "Report",
  "active": true
}
05

Check more than syntax before production

  • Confirm required fields exist.
  • Confirm numbers have not become strings.
  • Review null values and empty arrays.
  • Check payload size after minification.
  • Validate against a schema when the response is a contract.
06

Understand the parser messages

When validation fails, the message tells you where to look. "Unexpected token" points at a character the parser did not expect, "Unexpected end of JSON input" means the document stops early, and "Trailing comma" names the exact rule that strict JSON violates.

Each message maps to a concrete fix. The JSON error reference explains the common messages with broken and corrected examples, and the JSON repair tool applies conservative fixes you can review before using the result.

07

Run this workflow in the JSON formatter

  1. 1

    Paste or open the JSON document in the JSON formatter. Files up to 25 MB are read locally.

  2. 2

    Choose an indentation and run the formatter. The document is re-parsed, so any syntax error is reported immediately.

  3. 3

    Switch to the tree or table view to inspect structure and types before you trust the output.

  4. 4

    For schema checks, pass the same document to the JSON schema validator with a schema file.

08

Frequently asked questions

Is formatting safe for my data?

Yes. Formatting only re-indents and re-orders keys; it never changes values. Validation runs a strict parse so the output is guaranteed to be valid JSON when the tool reports success.

What does "strict JSON" reject that my editor accepts?

JavaScript object literals are looser than JSON. Strict JSON rejects trailing commas, single-quoted keys and strings, comments, and unquoted keys.

Does formatting upload my document?

No. The formatter reads the file or pasted text in your browser and formats it locally. Nothing is uploaded or stored.

What is the difference between format and minify?

Formatting adds indentation and line breaks for reading; minifying removes all whitespace for the smallest payload. Both produce the same data.

Jump to tool

Apply this workflow in the Json Formatter tool

Open tool