tools / json
json/
Format, minify, validate, escape and sort JSON keys, validated live as you type.
Input
Result
What is JSON
JSON is a text data format defined by RFC 8259 whose values can only be objects, arrays, strings, numbers or the three literals true, false and null. This page validates it with the browser's JSON.parse and formats, minifies, sorts keys, escapes and unescapes it.
How it works: parse, then write it out again
Both formatting and minifying first read the text into data with JSON.parse and then write it back with JSON.stringify: formatting indents with 2 spaces, 4 spaces or a tab, and minifying removes all whitespace between tokens. RFC 8259 allows only 4 whitespace characters (space, tab, line feed and carriage return), so removing them does not change the data.
RFC 8259 sets no limit on the range or precision of numbers; it only notes that between programs that handle numbers as IEEE 754 double precision, only integers whose absolute value does not exceed 2^53−1 are guaranteed to read as the same value. The browser's JSON.parse reads numbers as double precision.
Example
Minifying removes the indentation and line breaks and keeps the keys in their original order; with "Sort keys" checked, the same input puts a before b.
- Input
{ "b": [1, 2], "a": true }- Output
- {"b":[1,2],"a":true}
- Input
{ "b": [1, 2], "a": true }- Output
- {"a":true,"b":[1,2]}
Sources
FAQ
JSON validation says "Unexpected token" or "Invalid JSON". What's wrong?
Most often the text is a JavaScript or Python literal rather than standard JSON. Typical causes: single quotes, keys without double quotes, a trailing comma after the last item, // or /* */ comments, NaN or undefined (and Python's True or None), and curly quotes copied from a chat app. The reported position is where the parser got stuck; the real cause may be just before it.
How do I read the line and column in the error message?
Lines and columns start at 1. The position is taken from the browser's error when it has one; when it doesn't (Safari, for example), the tool scans the text itself to find the first bad character. The text after "·" is the browser's own JSON.parse message, so its wording differs between browsers and isn't translated here.
How do I turn \u4e2d\u6587 escapes in JSON into readable text?
Just click "Format" or "Minify". The tool parses the JSON and writes it back out, and \uXXXX sequences inside strings become the actual characters. If the whole thing is an escaped string (wrapped in quotes and full of \"), use "Unescape" first. Going the other way, turning non-ASCII text into \u form, isn't supported; "Escape" only handles quotes, backslashes, line breaks and similar characters.
What's the difference between "Escape" and "Unescape"? How do I restore a string full of \" from an API?
"Escape" turns text into something that can sit inside a string (a backslash before quotes, line breaks become \n), without the surrounding quotes. "Unescape" does the reverse. For API output full of \", choose "Unescape"; it works with or without the outer quotes. Then click "⇄ Use result as input" and it switches to "Format" for you.
Long numbers (like snowflake IDs) change at the end after formatting. What can I do?
Integers above 2^53 (9007199254740991) can't be represented exactly in JavaScript, so JSON.parse has already lost precision when reading them, and the last digits often turn into zeros. When you format or minify, the page shows a warning listing up to 5 positions. To keep such values intact, have the data source output these IDs as strings (in double quotes).
After formatting, 1.0 became 1 and a duplicate key disappeared. Why?
Formatting and minifying parse the JSON and write it back out, so numbers are rewritten the JavaScript way: 1.0 becomes 1, 1E2 becomes 100, 0.10 becomes 0.1 and -0 becomes 0. The values stay the same. If an object has the same key twice, only the last one is kept, with no warning.
How does "Sort keys" order things? Do arrays change?
Keys at every level are sorted by character code, with uppercase letters before lowercase, and other scripts by code point rather than dictionary order. Array items keep their order. Purely numeric keys (like "2" and "10") are an exception: JavaScript always puts them first, in numeric order, so they are moved to the front even when "Sort keys" is off.
How large can the JSON be? Is my data uploaded?
There's no fixed size limit. Above 1 million characters, processing is delayed by about 0.6 seconds after you type, and very large text is mainly limited by browser memory. Everything runs in your browser; the page sends no requests with your content and doesn't store what you enter.