# 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.

- Page: https://codethatmoves.com/tools/dev/json-formatter/
- Site: Code That Moves
- Category: Developer tools
- Free, runs in the browser, nothing is uploaded (files you drop in stay on your device)
- Last checked: 2026-11-03

## What it does

- Formats JSON with 2 spaces, 4 spaces or tabs, or minifies it, with syntax colours and line numbers
- Strict validation against RFC 8259 with the line, column and the line itself for every error
- Go to error puts the cursor on the exact character in your input
- Fixes common mistakes: comments, trailing commas, single quotes, unquoted keys, NaN and Infinity, and Python True, False and None
- Warns about duplicate keys with their path, ignores a byte order mark and unescapes stringified JSON
- Sorts keys, shows a collapsible tree and writes TypeScript interfaces
- Keeps big numbers exactly as written, and nothing is uploaded

## How to use it

1. Paste JSON into the left box, drop a .json file, or try the sample.
2. Choose 2 spaces, 4 spaces, tabs or Minify. Turn on Sort keys if you want them in order.
3. 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.

## Reference data

| Common mistake | Why it is invalid | Fix |
| --- | --- | --- |
| Trailing comma | A comma is allowed only between items | Remove the last comma |
| Comment | JSON has no comments | Remove it |
| Single quotes | Strings and names need double quotes | Use double quotes |
| Unquoted key | Property names must be strings | Put the name in double quotes |
| undefined, NaN, Infinity | They are not JSON values | Use null |
| Leading zero (007) | A number cannot start with 0 unless it is 0 | Remove the zero or use a string |

## Specs and sources

- [RFC 8259: The JSON data interchange format](https://datatracker.ietf.org/doc/html/rfc8259)
- [ECMA-404: The JSON data interchange syntax](https://ecma-international.org/publications-and-standards/standards/ecma-404/)
- [MDN: JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)

## 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.
