JSON formatter and validator

Format, validate, minify and sort JSON, see the exact line of any error, and generate TypeScript types from a sample. Everything runs in your browser; nothing is uploaded.

Result
The formatted result appears here.

How to use it

Paste JSON into the left box. It is checked as you type: valid JSON is formatted on the right, and invalid JSON shows the exact line and column of the first problem with a pointer under it.

Minify removes all whitespace for smaller payloads. Sort keys orders object keys alphabetically at every level, which makes two JSON files easy to compare in a diff. To TypeScript turns a sample response into interfaces; keys missing from some array items become optional.

Common JSON errors

  • A comma after the last item in an object or array (allowed in JavaScript, not in JSON).
  • Single quotes around keys or strings. JSON only accepts double quotes.
  • Unquoted keys, comments, undefined, or NaN.
  • A raw line break inside a string; write it as \n.

Questions

Is my JSON sent to a server?

No. Parsing and formatting happen in your browser with JavaScript. You can disconnect from the internet after the page loads and it still works.

Why does it say "Trailing comma"?

JSON does not allow a comma after the last element of an object or array. Delete the comma just before the closing } or ].

How large a file can it handle?

Several megabytes is fine on a laptop. Very large files may make the page slow because the result is re-rendered as you type.

How are optional fields chosen in the TypeScript output?

When an array contains several objects, a key that is missing from any of them is marked optional with ?. Values that can be different types become a union such as string | null.

More tools