Skip to content
Technology·1 min read·

JSON validator and minifier

Check that text is valid JSON and print it on one line, with the size before and after.

The answer

Valid JSON is parsed and printed without extra space. Invalid JSON, including comments and trailing commas, stops with an error. The check does not repair the text.

Result

Minified JSON

{"ok":true}

Check

Valid JSON

Characters before

14

Characters after

11

What do you want to do next?

How this works

The parser accepts objects, arrays, strings, numbers, true, false, and null. It does not accept comments, trailing commas, or single-quoted strings, because those are not JSON.

Minifying does not sort keys or change numbers beyond what the parser’s normal number reading does. The character counts show the pasted length and the minified length.

Practical steps

  1. 1

    Paste the JSON.

  2. 2

    If the check says it is valid, copy the minified line.

  3. 3

    If it fails, remove comments and trailing commas and try again. This page will not guess a repair.

Examples

  • { "ok": true }

    The minified text is {"ok":true}, and the check says valid JSON.

Common mistakes

  • ×

    Treating a trailing comma as a minor style issue. The parser has to reject it.

Frequently asked questions

Will this pretty-print instead?

No. The JSON formatter on this site indents JSON. This page removes the extra space.

Does valid mean the values are correct?

No. It means the text is legal JSON. It does not know which keys your program requires.

Sources