JSON Formatter
Paste JSON to format, validate or minify it, see the exact line and column of an error, browse a tree and get TypeScript types.
Last checked
Files never leave your device. Everything runs in this tab.
Your JSON
Result
- Format with 2 spaces, 4 spaces or tabs, or minify
- Errors with the line, column and the line itself
- Fix comments, trailing commas, single quotes and Python values
- A collapsible tree and TypeScript types
- Big numbers kept exactly, digit for digit
How to use it
- Paste JSON into the left box, drop a .json file, or try the sample.
- Choose 2 spaces, 4 spaces, tabs or Minify. Turn on Sort keys if you want them in order.
- If the JSON is invalid, press Go to error to jump to the problem, or Fix common issues. Then copy, download or copy it as an escaped JSON string.
What it checks and why
Most JSON errors are small: a comma left after the last item, a key without quotes, a comment, a single quote. The error from JSON.parse in a browser or a script is often vague and differs between engines. This tool reads the text itself and stops at the exact character, then shows the line, the column and the line with a caret under the problem, with a short note on what to change.
It follows the JSON standard strictly, which is also why it can help with code you pasted from JavaScript. When it finds comments, trailing commas, single-quoted strings, unquoted keys, values such as undefined or NaN, or Python's True, False and None, the Fix common issues button rewrites them into valid JSON and tells you what it changed. Text inside strings is never touched.
RFC 8259 says the names in an object should be unique, but it does not forbid duplicates, and parsers disagree on which value wins. The tool lists every duplicate key with its path, such as $.tools[1].slug, so you can see it before a parser silently drops one. Files saved by Windows Notepad or Excel often start with an invisible byte order mark; it is ignored instead of reported as an error. When the whole input is a JSON string that holds more JSON, as in many log lines, one click unescapes it.
Formatting works on the text, not on a JavaScript object, so numbers and strings come out exactly as written. A large id such as 12345678901234567890 stays intact, where JSON.parse would round it. The tool warns you when a number is too large for JavaScript to hold, because code that reads the JSON will round it. The tree view and the TypeScript output come from the same parsed data.
Specs and sources
Limits
- The TypeScript types are inferred from this one sample. A field that is missing or has another type elsewhere will not be seen.
- The tree view shows the first 1500 values. The text view has all of them.
- Files up to 20 MB are read, and very large text is slow to show, so the text view is cut after 200 000 characters. Copy and download hold everything.
- Fix common issues handles the usual cases. Text that is broken in other ways has to be fixed by hand.
Questions
- How do I find the error in my JSON?
- Paste it and read the message. The tool gives the line and column, shows the line with a caret under the problem and says what to change, for example that a comma before a closing bracket is not allowed.
- Why is a trailing comma invalid in JSON?
- The JSON standard allows a comma only between items. JavaScript accepts a trailing comma in code, which is why it often slips in when you copy from source. The Fix button removes it.
- Can JSON have comments?
- No. Standard JSON has no comments, and parsers reject them. Some config formats such as JSONC allow them, but data sent to an API must not contain them. The tool can strip them for you.
- Why does a big number change when I parse it in JavaScript?
- JavaScript stores numbers as 64-bit floating point, which holds integers exactly only up to 9007199254740991. A larger id is rounded. Send such ids as strings, and this tool keeps them as written.
- How do I unescape a JSON string?
- Paste the string with its quotes, for example "{\"a\":1}". The tool sees that the value is itself JSON and offers Unescape the inner JSON. To go the other way, format your JSON and press Copy as a JSON string.
- Are duplicate keys allowed in JSON?
- RFC 8259 says names should be unique but does not forbid repeats, so a parser may keep the first value, the last or reject the text. JavaScript's JSON.parse keeps the last. The tool warns and shows where each duplicate is.
- How do I open a JSON file?
- JSON is plain text, so any text editor opens it, and browsers show it too. To read a large or minified file, open it in an editor, copy everything and paste it here to format and validate it.
- What is the difference between JSON and a JavaScript object?
- JSON is a text format with stricter rules: keys in double quotes, no functions, no undefined, no comments and no trailing commas. JSON.parse() turns JSON text into a JavaScript object and JSON.stringify() turns an object back into JSON text.