How to format and validate JSON
- Paste your JSON into the Input box — from an API response, a log file or a config file. It is formatted automatically.
- Choose 2 spaces, 4 spaces or tabs for indentation.
- Click Minify to compress it to a single line, or Sort keys to order object keys alphabetically.
- If the JSON is invalid, the status line shows the error with its line and column, and the problem line is highlighted.
- Copy the result or download it as a
.jsonfile.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. It is the default format for web APIs, and is used in configuration files such as package.json, tsconfig.json and many cloud services. JSON is defined by RFC 8259 and ECMA-404.
JSON supports six data types:
| Type | Example |
|---|---|
| String | "hello" (double quotes only) |
| Number | 42, -3.14, 1e10 |
| Boolean | true, false |
| Null | null |
| Object | {"key": "value"} |
| Array | [1, 2, 3] |
Most common JSON errors and how to fix them
1. Trailing commas
{"a": 1, "b": 2,} is invalid. Remove the comma after the last property or array item.
2. Single quotes
{'name': 'Ann'} is valid JavaScript but invalid JSON. Keys and strings must use double quotes: {"name": "Ann"}.
3. Unquoted keys
{name: "Ann"} must be written {"name": "Ann"}.
4. Comments
JSON has no comment syntax. Remove // ... and /* ... */, or move the note into a field like "_comment".
5. Invalid values
undefined, NaN, Infinity, functions and dates are not JSON values. Use null, a number, or an ISO date string like "2026-01-31T12:00:00Z".
6. Unescaped characters in strings
Double quotes, backslashes and line breaks inside a string must be escaped: \", \\ and \n.
Format JSON from the command line or code
- JavaScript:
JSON.stringify(JSON.parse(text), null, 2) - Python:
python3 -m json.tool data.json - jq:
jq . data.jsonto format,jq -c . data.jsonto minify - VS Code:
Shift + Alt + F(Windows) orShift + Option + F(Mac)
JSON vs XML vs YAML
JSON is compact and maps directly to objects in almost every programming language, which is why it dominates web APIs. XML is more verbose but supports attributes, namespaces and schemas, and is still common in enterprise and document formats. YAML is a superset of JSON designed for human-edited configuration files (Docker Compose, Kubernetes, GitHub Actions) and supports comments, but its indentation rules can cause subtle errors.
More JSON tools
The mode menu at the top of the tool also converts between formats. Each has its own page with a sample and a short guide:
Frequently asked questions
Is it safe to paste sensitive JSON here?
Yes. Formatting and validation use your browser's built-in JSON.parse and JSON.stringify. Nothing is uploaded, logged or stored on a server, so API responses with tokens or customer data stay on your machine.
Why is my JSON invalid?
The most common causes are: trailing commas after the last item, single quotes instead of double quotes, unquoted keys, comments (// or /* */), and special values like undefined or NaN. The validator points to the line and column where parsing failed.
What does minify do?
Minifying removes all unnecessary whitespace and line breaks, producing the smallest valid JSON. It is useful for sending data over the network or storing it compactly.
Does JSON allow comments?
No. Standard JSON (RFC 8259) does not support comments. Formats like JSONC (used by VS Code) and JSON5 allow them, but they must be stripped before a strict JSON parser will accept the file.
Does sorting keys change my data?
Sorting only changes the order of keys inside objects. Arrays keep their order. JSON objects are unordered by definition, so the data means the same thing — but sorted keys make diffs and comparisons much easier.
Is there a size limit?
There is no fixed limit; it depends on your device's memory. Files of several megabytes format in well under a second on a modern computer.


