JSON Formatter
Paste or upload JSON to validate, format, minify, and explore it. Your JSON is processed locally in your browser.
How it works
Your JSON is parsed and transformed entirely in your browser, using the same JSON.parse/JSON.stringify the browser already provides; nothing is sent to a server. Format, Minify, and the tree/code views all work from that one parsed value.
What this tool does
Format, validate, minify, and inspect JSON without leaving the browser.
How to use
- Paste JSON or upload a JSON file.
- Choose Format or Minify.
- Copy or download the resulting JSON.
Why your JSON is invalid
JSON is stricter than the JavaScript object syntax it looks like. These are the errors behind almost every "Invalid JSON" message. Each was checked against the browser's own JSON parser, which this formatter uses.
| You wrote | Why it fails | Valid version |
|---|---|---|
{"a": 1,} |
Trailing comma after the last item | {"a": 1} |
{'a': 1} |
Single quotes. JSON only allows double quotes | {"a": 1} |
{a: 1} |
Unquoted key | {"a": 1} |
{"a": 1 // note} |
Comments aren't allowed in JSON | Remove the comment, or use a format that allows them (JSONC, JSON5, YAML) |
{"a": NaN} |
NaN, Infinity and undefined aren't JSON values |
Use null or a string |
{"a": 01} |
Leading zeros aren't allowed | {"a": 1} or {"a": "01"} |
| A real line break inside a string | Control characters must be escaped | "line 1\nline 2" |
{"a": 1} {"b": 2} |
Two top-level values. That's JSON Lines (NDJSON), not one JSON document | Wrap them in an array: [{"a": 1}, {"b": 2}] |
The error message gives the line and column where the parser gave up. The real mistake is usually just before that point: a missing comma on the previous line shows up as an error at the start of the next one.
Things that are valid but may surprise you
Duplicate keys. {"a": 1, "a": 2} is accepted, and the last value wins (a becomes 2). Formatting shows only one a. If your data has duplicate keys, some of it is silently being dropped by whatever reads it.
Numbers are normalized. 1.0 becomes 1 and 1e3 becomes 1000 after formatting. The value is the same; only the notation changes.
Very large integers. JavaScript numbers are exact only up to 9,007,199,254,740,991 (2^53 − 1). Bigger integers, such as 64-bit database IDs, are rounded by most JavaScript tools: 12345678901234567890 becomes 12345678901234567000. This formatter keeps the original digits in the Format and Minify output when your browser supports it (current Chrome, Edge and Firefox), and warns you if it can't. If you control the API, send large IDs as strings.
A byte order mark. Files saved by some Windows editors start with an invisible BOM character, which strict parsers reject. This formatter ignores it.
Format, minify or validate?
| Action | Use it when |
|---|---|
| Format | You need to read or review JSON: API responses, config files, logs. Adds 2-space indentation and line breaks |
| Minify | You're sending or storing JSON and size matters. Removes every insignificant space and line break |
| Validate (automatic) | You only need to know whether it parses. The status line updates as you type |
| Tree view | You're exploring a large, deeply nested document and want to expand only the parts you care about |
Validation here checks syntax only. To check that the data has the right structure (required fields, types, allowed values), use the JSON Schema validator. To pull specific values out of a large document, use the JSONPath evaluator. To compare two versions, use JSON Diff.
FAQ
Is my JSON uploaded to a server?
No. Parsing and formatting happen in your browser. Nothing you paste or upload is sent to Docspira, so it's safe for API responses with tokens or customer data.
How big a file can I format?
Files of several megabytes work fine. Very large arrays (tens of thousands of items) start collapsed in the tree view so the page stays responsive; the formatted code view is unaffected.
Can it fix my JSON automatically?
No. It tells you exactly where the problem is, and the table above covers the usual fixes. Automatic "repair" guesses what you meant, and a wrong guess can silently change your data.
Does formatting change my data?
No, apart from notation: 1.0 is written as 1, and duplicate keys collapse to the last value, exactly as any JSON parser would read them.
What's the difference between JSON and a JavaScript object?
JSON is a text format with stricter rules: double-quoted keys and strings, no trailing commas, no comments, no functions, no undefined. Every valid JSON document is a valid JavaScript expression, but not the other way around.
Formatting and validation
Formatting and the tree view use the same parsed JSON value, so invalid JSON is reported before any output is created.
Privacy
This tool runs in your browser; the text or file you choose is not uploaded for processing. Read the privacy details.