JSON Formatter & Validator
Format JSON so it is easy to read, or minify it by removing whitespace. The syntax is checked as you type, and if the JSON is invalid, the line, column, and cause of the error are shown.
Large numbers, the way decimals are written, and the order of keys are kept exactly as entered. Everything happens in your browser. Nothing you enter is sent to a server.
Examples:
What is JSON?
JSON (JavaScript Object Notation) is a text format for representing data (RFC 8259). It is used wherever programs exchange data, such as Web API requests and responses, configuration files, and logs.
JSON from API responses and logs is often a single line with no spaces or line breaks, which is hard to read as is. Formatting adds indentation and line breaks according to the nesting depth, so the structure is clear at a glance. Conversely, minifying removes whitespace to make the data smaller for sending or storing.
JSON syntax rules
JSON has the following 6 types of values. Objects and arrays can contain other values nested inside them.
| Type | Examples | Description |
|---|---|---|
| String | "Hello" "\u3042" "a\nb" | Enclosed in double quotes. Escape special characters with \, such as \n for a line break and \" for ". |
| Number | 42 -1.5 1e10 | Written in decimal. A leading 0 (01), a +, or a bare decimal point (.5, 1.) is not allowed. |
| Boolean | true false | true or false, in lowercase. |
| null | null | Represents the absence of a value, in lowercase. |
| Object | {"name": "a", "age": 20} | Pairs of “key: value” separated by commas inside { }. Keys are strings in double quotes. |
| Array | [1, "a", true] | Values separated by commas inside [ ]. |
Some things that are allowed in JavaScript are not allowed in JSON: comments, a comma after the last element (trailing comma), strings in single quotes, keys without double quotes, and NaN, Infinity, and undefined.
Only spaces, tabs, and line breaks can be used as whitespace. Other whitespace characters, such as the ideographic (full-width) space, cause an error.
Common errors and how to fix them
Common mistakes and the errors this tool shows for them. The error position is where the first mistake was found. When a comma or closing bracket is missing, the actual cause may be earlier than the position shown.
| Input | Error shown |
|---|---|
| {"a": 1, "b": 2,} | Line 1, character 16: There is a comma after the last element (trailing comma). |
| {'a': 1} | Line 1, character 2: Strings and keys must be enclosed in double quotes ("), not single quotes ('). |
| {a: 1} | Line 1, character 2: Enclose the key “a” in double quotes. |
| {"a": 1 "b": 2} | Line 1, character 9: Expected “,” or “}”, but found “"”. |
| {"a": NaN} | Line 1, character 7: “NaN” cannot be used as a JSON value (allowed values include strings, numbers, true, false, and null). |
| {"a": 01} | Line 1, character 7: “01” is not a valid number. |
| {"path": "C:\Users"} | Line 1, character 13: “\U” is not a valid escape in a string (write \ as \\). |
| // comment {"a": 1} | Line 1, character 1: Comments are not allowed in JSON. |
| {"a": 1}} | Line 1, character 9: There is “}” after the value. The whole JSON must be a single value (such as an object or array). |
JSON vs. JSONC and JSON5 (comments and trailing commas)
Configuration files such as tsconfig.json and VS Code’s settings.json are sometimes written in JSONC (JSON with Comments), which adds comments and trailing commas to JSON. JSON5 also allows strings in single quotes and keys without quotes. These are not valid JSON, so programs that read JSON report an error.
Select “Remove comments” and “Remove trailing commas” to remove them and format the input as valid JSON. Removed comments are not kept in the result. Strings in single quotes and keys without quotes are not fixed and are reported as errors.
Large numbers and key order
When read with JavaScript’s JSON.parse, integers larger than 2^53 (9,007,199,254,740,992) are rounded, so 12345678901234567890 becomes 12345678901234567000. Also, 1.50 becomes 1.5 and 1e3 becomes 1000. This tool handles numbers exactly as written, so formatting never changes how a number is written.
In JavaScript objects, keys made only of digits, such as "10" and "2", are moved to the front, but this tool keeps keys in the order they were entered. To sort them, select “Sort keys”. The order of arrays is never changed.
Formatting JSON in programming languages and commands
How to format and minify JSON in major languages and commands. Note that some languages round large numbers or change the order of keys when reading JSON.
| Language / tool | Code / action | Conversion |
|---|---|---|
| JavaScript | JSON.stringify(value, null, 2) | Format |
| JavaScript | JSON.stringify(value) | Minify |
| Python | json.dumps(value, indent=2, ensure_ascii=False) | Format |
| Python | json.dumps(value, separators=(',', ':')) | Minify |
| Python | python -m json.tool input.json | Format |
| jq | jq . input.json | Format |
| jq | jq -c . input.json | Minify |
| PHP | json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) | Format |
| Go | json.Indent(&buf, data, "", " ") | Format |
| Go | json.Compact(&buf, data) | Minify |
| Ruby | JSON.pretty_generate(value) | Format |
| Ruby | JSON.generate(value) | Minify |
| VS Code | Shift+Alt+F(macOS: Shift+Option+F) | Format |
How to use
- Choose “Format” or “Minify”. When formatting, choose the indentation.
- Paste JSON into the input box. The syntax is checked and the result is shown immediately.
- If an error is shown, check the line and column, and the ^ under the line shown below the message, then fix it.
- Click “Copy” to copy the result to the clipboard. Click “Move result to input” to keep converting, for example to minify the formatted result.
FAQ
Is the JSON I enter sent to a server?
No. Formatting and validation happen entirely in your browser, so you can safely paste API responses, configuration files, and similar data.
How do I read the error position?
The position of the first mistake found is shown as a line and column, such as “Line 3, character 15”, followed by the line with the error and a ^ pointing to the position. When a comma or closing bracket is missing, the actual cause may be on an earlier line.
Does the order of keys change?
No. Keys are formatted in the order they were entered, including keys made only of digits. Select “Sort keys” to sort the keys in each object alphabetically (by character code).
Do large numbers or decimal places change?
No. Numbers are handled exactly as written, so integers larger than 2^53, such as IDs, are not rounded, and forms such as 1.50 and 1e3 are kept as is.
I got a warning about duplicate keys.
The same key appears more than once in the same object. This is valid JSON syntax, so it is not an error, but programs handle it differently; for example, some keep only the last value. Check whether it is intended.
Can I format JSON with comments or trailing commas?
Yes. Select “Remove comments” and “Remove trailing commas” to remove them before formatting. This is useful for turning JSONC files such as tsconfig.json into valid JSON.
How large can the JSON be?
You can enter up to 1,000,000 characters, nested up to 1,000 levels deep.
What is the difference between formatting and minifying?
Formatting adds indentation and line breaks to make JSON easy for people to read. Minifying removes spaces and line breaks to put it on a single line and make the data smaller. Neither changes the content of the data.