Skip to content
gohacks.dev
Standard Library

JSON Formatter and Validator

Pretty-print, minify and validate JSON, with the line and column of the first error. Sort keys to make two payloads comparable.

Free · No sign-up · Your inputs stay in your browser

Input

Format and validate JSON

Output

Valid JSON

Top-level object, 213 characters

Runs in this browser. Nothing you paste is sent to a server.

Why JSON fails to parse

Most invalid JSON is valid JavaScript: a trailing comma after the last item, single-quoted strings, unquoted keys or a comment. RFC 8259 allows none of them. The error message names the position of the first character the parser could not accept, which is usually one character after the real mistake.

When to sort keys

JSON objects are unordered, but diff tools are not. Sorting keys before comparing two API responses or two lock files hides differences that do not matter and shows the ones that do.

Large numbers

JavaScript numbers are IEEE 754 doubles, so integers above 253 (9007199254740992) lose precision when parsed. A 64-bit database ID formatted here can come back with different last digits; send such IDs as strings.

Share

Frequently asked questions

Why does my JSON have an "Unexpected token" error?
The parser met a character JSON does not allow at that point, most often a trailing comma, a single quote, an unquoted key or a comment. Check the character just before the reported position.
Does formatting change my data?
Only whitespace and, if you choose it, key order. Values are kept, except integers beyond 2^53, which JavaScript cannot represent exactly.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools