How to use the JSON formatter
Paste your JSON into the top box and press Format. If the JSON is valid you get a neatly indented copy in the result box, ready to copy back into your editor, a bug report or a Slack message. If it is not valid, you get the parser's error plus the line and column where things went wrong, which is usually the fastest way to find a missing comma.
- Format pretty-prints with 2 spaces, 4 spaces or tabs.
- Minify strips every unnecessary space and line break. Handy before pasting a payload into a curl command or an environment variable.
- Validate only checks the input and tells you what kind of value it found (an object with 12 keys, an array of 40 items, and so on).
- Sort keys orders object keys alphabetically at every depth. This is surprisingly useful when you want to compare two API responses with the text diff tool, because key order no longer creates noise.
Reading the error messages
Browsers give slightly different wording, but most JSON errors fall into a handful of buckets. "Unexpected token" near the end of an object almost always means a trailing comma, which JavaScript allows but JSON does not. "Unexpected token '" means single quotes were used; JSON strings must use double quotes. "Unexpected end of JSON input" means a bracket or brace was never closed, which often happens when a log line was truncated.
When the error points at a line, look at that line and the one above it. The parser only notices a problem when it reaches the next character it cannot accept, so the real mistake is often one step earlier. We wrote a longer walkthrough in why your JSON won't parse.
Things JSON does not allow
JSON looks like JavaScript, but it is stricter. These are all invalid and will be rejected:
- Comments (
// like thisor/* this */) - Unquoted keys such as
{name: "Ada"} undefined,NaNandInfinity- Leading zeros in numbers, like
007
If you are working with a config file that has comments, it is probably JSON5 or JSONC (the format VS Code uses for settings). Remove the comments first, then format it here.
Is my data private?
Yes. The formatter uses the JSON.parse and JSON.stringify functions built into your browser. There is no server-side processing, so API keys, customer records or anything else you paste never leave your machine. You can even load the page, disconnect from the internet, and keep using it.
Frequently asked questions
What is the difference between formatting and validating JSON?
Validating only checks whether the text is legal JSON. Formatting validates first and then rewrites the text with consistent indentation so humans can read it.
Why does my JSON work in JavaScript but fail here?
JavaScript object literals allow single quotes, unquoted keys, trailing commas and comments. Strict JSON allows none of those, so code that runs fine in a .js file can still be invalid JSON.
Is there a size limit?
There is no fixed limit. Files of a few megabytes format instantly; very large files depend on how much memory your browser has available.
Does sorting keys change my data?
No. Object key order has no meaning in JSON, so sorted output is equivalent to the original. Array order is never changed.