JSON Formatter

JSON is unforgiving about syntax — one missing comma or unmatched bracket makes the whole document invalid. This validates and pretty-prints it instantly, or points out exactly what's wrong if it isn't valid.

Inputs

Result

Valid JSON

{ "name": "CalculatorHub", "calculators": 500 }

How the json formatter works

The input is parsed strictly according to the JSON specification — if parsing succeeds, the result is re-serialised with consistent indentation for readability.

If parsing fails, the specific error message (including what was expected and roughly where the problem is) is shown rather than a generic failure.

Worked example: valid vs invalid JSON

  1. {"name":"CalculatorHub","calculators":500} is valid JSON and reformats cleanly with proper indentation.
  2. Removing the closing brace, or adding a trailing comma after the last property, produces an 'Invalid JSON' result with a specific parser error message pinpointing the issue.

Common mistakes to avoid

Leaving a trailing comma after the last item in an object or array

Unlike some programming languages, standard JSON strictly disallows a comma after the final item in an object or array — this specific mistake is one of the most common reasons seemingly correct-looking JSON fails to parse.

Using single quotes instead of double quotes for strings

JSON requires double quotes for all string values and keys — single-quoted strings, while valid in JavaScript object literals, are not valid JSON and will cause a parse error here.

Frequently asked questions

Why is JSON so strict about trailing commas and quote types compared to JavaScript?

JSON is a data-interchange format specification separate from JavaScript's own more flexible object literal syntax — it deliberately trades some convenience for strict, unambiguous parseability across every language and platform that implements a JSON parser.

How does 'pretty-printing' help beyond just validating?

Consistent indentation makes nested structures (objects within objects, arrays of objects) visually clear at a glance, which is much harder to follow in minified, single-line JSON despite it being equally valid.

What does the specific error message actually tell me?

It typically identifies what character or token the parser expected versus what it actually found, and roughly where in the string that mismatch occurred — a strong starting point for locating the specific syntax problem.

Can JSON contain comments?

No — the standard JSON specification does not support comments at all, which surprises people coming from JavaScript or other languages where comments are common; any comment-like text will cause a parse failure.

Related calculators