How to use
- Paste your JSON into the input editor, or press Open file to load a .json file. With Auto-format on, the result updates as you type.
- Pick the indentation (2 spaces, 4 spaces or tab) and press Format, or press Minify to remove all extra whitespace. Tick Sort keys to order the keys alphabetically.
- Copy or download the result. Use the arrows next to the line numbers to fold objects and arrays. If the JSON is invalid, the status line gives the line and column, and the error is underlined in the input.
Examples
{"name":"MultiKit","tools":[1,2]}→ {
"name": "MultiKit",
"tools": [
1,
2
]
}Format with 2-space indentation.{
"a": 1,
"b": [1, 2]
}→ {"a":1,"b":[1,2]}Minify removes every space and line break that is not inside a string.{a: 1}→ Error: the parser rejects it, because JSON keys must be in double quotes.
How it works
The tool uses your browser’s built-in JSON parser (JSON.parse) to read the text and JSON.stringify to write it back, so it accepts exactly the JSON syntax that browsers accept: double-quoted strings and keys, no comments, no trailing commas.
If parsing fails, the message comes from the browser’s parser. The wording differs between browsers. Chrome and Firefox name the position, and the tool turns it into a line and column and underlines it in the input; Safari gives no position, so only the message is shown.
The status line also shows the type of the document, how many keys or items it has, how deeply it is nested, and its size before and after.
Formatting writes each key and array item on its own line, indented with the amount you choose. Minifying writes the same data with no whitespace outside strings.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- CodeMirror, the open-source editor used here
- MDN: JSON.parse()
Frequently asked questions
- Why is my JSON invalid?
- The most common causes are single quotes instead of double quotes, unquoted keys, a trailing comma after the last item, and comments. Strict JSON allows none of them.
- Does formatting change my data?
- The tool parses your JSON and writes it back out. Values are kept, but duplicate keys collapse to the last one, and numbers larger than 9007199254740991 (2^53 - 1) can lose precision because JavaScript stores numbers as 64-bit floats.
- Will the key order change?
- Keys usually stay in the order you wrote them. The exception is keys that look like whole numbers, such as "10" or "2", which JavaScript moves to the front in ascending order.
- What does Sort keys do?
- It orders the keys of every object alphabetically, which makes two JSON documents easier to compare, for example in a diff tool. The order of items inside arrays never changes. Keys that look like whole numbers are still placed first by JavaScript.
- How large a file can I open?
- Files up to 10 MB. Very large documents can make the editor slow, because the whole text is held in your browser.
- What is the difference between format and minify?
- Format adds line breaks and indentation so people can read it. Minify removes them to make the text as short as possible, which is useful for sending or storing JSON.
- Is my JSON uploaded?
- No. Parsing and formatting run in your browser and the data is never sent to a server.