Free tool · Developer tools
JSON formatter and validator
Paste JSON to pretty-print it, minify it or check it. If something is wrong you get the line and column and a plain explanation. It all runs on your device, so nothing you paste is uploaded.
- Free
- No sign-up
- Runs in your browser
FormattedValid JSON, 15 lines.
- Top level: object
- 1 long number kept exactly
- Size
- 148 chars to 205 chars
- Lines
- 1 to 15
- Keys
- 9
- Depth
- 2
How to use the JSON Formatter
- Paste your JSON into Your JSON, or use Or choose a JSON file. The file is read on your device.
- Under What to do pick Format, Minify or Validate only. For Format, choose the Indent: 2 spaces, 4 spaces or a tab.
- Tick Sort keys A to Z to put every object's keys in order, or Accept comments and trailing commas to read a looser file.
- Read the Result, then press Copy or Download. If the JSON is wrong, the red message gives the line and column, and Show the error in the box selects the spot.
How do I format JSON online?
Paste the JSON and leave Format selected. The tool prints it again with one value per line and the indent you choose, so {"id":1,"tags":["a","b"]} becomes 7 lines ({ "id": 1, "tags": [ and so on), with each tag on its own line. Indenting changes only whitespace, which JSON ignores between values, so the data itself is the same.
Numbers and strings are printed exactly as you wrote them. The built-in JSON.parse that many online formatters call turns every number into a 64-bit float, so {"a":12345678901234567890,"b":12.50} comes back as {"a":12345678901234567000,"b":12.5}. This formatter keeps every digit and gives {"a":12345678901234567890,"b":12.50}. RFC 8259 says integers from -(2^53)+1 to (2^53)-1 are the range that software can exchange reliably, and that very large or precise numbers may not survive in other software, so a chip under the result tells you when a number is longer than a float can hold. The id 9007199254740993 in the example is one of them.
Large input is fine. The result is worked out a moment after you stop typing, and the box shows the first 200,000 characters while Copy and Download carry all of it. Text over 10 MB is refused so the page stays responsive. Sort keys A to Z orders the keys of every object at every depth, which makes two versions of a file easier to compare line by line. The order of items in an array is never changed. For example {"b":2,"a":{"z":1,"y":2}} with sorting on becomes {"a":{"y":2,"z":1},"b":2}.
How do I find the error in my JSON?
When the text is not valid, the result shows the line and column of the first mistake, a short explanation and the line itself with a caret under the spot. Show the error in the box selects that character in your text. The parser stops at the first problem, so fix it and, if there is another one, it appears next.
The usual causes are a comma after the last item ({"a":1,}), a missing comma between two items, single quotes instead of double quotes, a property name without quotes ({a:1}), a number with a leading zero or in hex, values such as undefined, NaN or Infinity, and a string with a raw line break in it. A string whose closing quote is missing is reported on the line where that string starts. If the error is at the end of the text, a bracket was never closed, and the message names the line where the open [ or { began.
The real slip can sit just before the reported spot, so read the line above the caret too. Typing in the box updates the result straight away, which is the quickest way to check a fix.
What do the common JSON error messages mean?
The table feeds each broken text to this tool and shows what it reports. The line and column count from 1. In a one-line example the column is the character position, so you can count along the text to see where the parser gave up.
| Mistake | Text | What the tool reports |
|---|---|---|
| A comma after the last item | {"a":1,} | line 1, column 7: Trailing comma: JSON does not allow a comma before "}". Remove it, or tick "Accept comments and trailing commas". |
| A missing comma | {"a":1 "b":2} | line 1, column 8: Expected "," or "}" but found """. A comma may be missing. |
| Single quotes | {'a':1} | line 1, column 2: Property names need double quotes, not single quotes: write "name". |
| A key without quotes | {a:1} | line 1, column 2: Property names must be in double quotes: write "name": value. |
| A leading zero | {"a":01} | line 1, column 6: Numbers cannot have leading zeros: write 7, not 07. |
| NaN, a value JSON does not have | {"a":NaN} | line 1, column 6: NaN and Infinity are not valid JSON. Use null or a string. |
| A bracket never closed | {"a":1 | line 1, column 7: The text ends before the object opened on line 1 is closed. Add a }. |
Fix the first error shown, then look again: the parser stops at the first problem, so a file with three mistakes shows them one at a time. A message that points at the end of the text almost always means a missing closing bracket or brace earlier in the file.
What is the difference between formatting and minifying JSON?
Both keep the data identical and change only the whitespace between values. Formatting adds line breaks and indentation so people can read the structure. Minifying removes every space and line break outside strings, so the text is as short as it can be for sending in a request or saving in a file. After Minify a chip shows how much smaller the text became. A space inside a string is data, so neither mode touches it.
The example order is 148 characters on one line, already without extra spaces. Formatted with 2 spaces it is 15 lines and 205 characters, 57 more. Minified it goes back to 148 characters. The chip reads "No whitespace to remove" for this input.
Validate only checks the syntax and shows the size, the number of keys and how deeply the data is nested, without printing the text again. Use it for a quick yes or no on a large file. All three modes use the same parser, so Format and Minify also tell you when the input is invalid.
Are comments or trailing commas allowed in JSON?
Not in standard JSON. RFC 8259 allows only whitespace between values, so a // comment, a /* */ comment or a comma before } or ] makes the text invalid, and so do single quotes, unquoted keys and numbers such as +1, .5 or 0x1F. JSON.parse follows this and refuses such text, which is why a file that looks fine to a person fails in code.
Some configuration files are written in a looser dialect, often called JSON with comments. Tick Accept comments and trailing commas to read one. The comments and extra commas are removed from the output and a chip says how many, so what you copy is standard JSON that every parser accepts.
Example: { // retry count "retries": 3, } has a comment and a trailing comma. With the option ticked the output is {"retries":3}. With it unticked the error is: line 2, column 3: Comments are not allowed in JSON. Remove it, or tick "Accept comments and trailing commas".
Duplicate keys are a different case. RFC 8259 says the names inside an object should be unique and that behavior is unpredictable when they are not; many parsers keep only the last one. This tool keeps all of them in the output and shows a chip with the count, so you can decide which to keep.
Is my JSON uploaded anywhere?
No. The parser is code inside this page. The text you paste, or the file you choose, is read by your browser and never sent over the network, and nothing is stored: reload the page and the box returns to the example. That makes it suitable for configuration files and API responses you would rather not paste into a site that works on a server. Remove live passwords and keys from the text before you share the output anywhere.
Use it with
- JSON Compare: diff two JSON documents.
- YAML to JSON: convert YAML and JSON both ways.
- Base64 Encoder Decoder: encode or decode Base64.
- SyntaxError: "undefined" is not valid JSON in a React app (a fix on this site)
- npm install fails with Unexpected end of JSON input (a fix on this site)
- json_decode() gives NULL for JSON that looks valid (a fix on this site)
- response.json() fails with Unexpected token '<' (a fix on this site)
Questions
How do I format JSON online?
Paste the JSON into the box with Format selected and pick an indent. The pretty-printed text appears under Result and can be copied or downloaded.
How do I find the error in my JSON?
The result gives the line and column of the first mistake with a plain explanation and the line shown with a caret. Show the error in the box selects that spot in your text.
What is the difference between formatting and minifying JSON?
Formatting adds line breaks and indentation for reading; minifying removes all whitespace outside strings to make the text short. The data is the same either way. The example order shrinks from 205 characters formatted to 148 minified.
Are comments allowed in JSON?
Not in standard JSON (RFC 8259). Tick Accept comments and trailing commas to read a file that has them; they are removed from the output.
Are trailing commas allowed in JSON?
No. A comma before a closing bracket or brace is a syntax error in standard JSON. For {"a":1,} the tool reports line 1, column 7: Trailing comma: JSON does not allow a comma before "}". Remove it, or tick "Accept comments and trailing commas".
Is my JSON uploaded anywhere?
No. It is parsed by code running in your browser, and nothing you paste or choose is sent or stored.
Sources
How this page was made: the tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations were drafted with AI help and checked against the tool's own output.