How to use the JSON formatter
- Paste your JSON into the input box, or type it directly.
- Choose an indentation style: 2 spaces, 4 spaces or tabs.
- Click Format to pretty-print, or Minify to strip all optional whitespace.
- If the input is invalid, the validator shows the error message together with the line and column where parsing failed.
- Optionally enable Sort keys to order object keys alphabetically, or convert the result to YAML or CSV.
- Copy the output and paste it wherever you need it.
Everything runs in your browser: your JSON is never uploaded to a server or stored, so it is safe to format API responses, configuration files and logs that contain private data.
What is JSON and why format it?
JSON (JavaScript Object Notation) is a lightweight, text-based data format standardised in RFC 8259 and ECMA-404. It is built from just six kinds of value: objects ({}), arrays ([]), strings, numbers, the booleans true and false, and null. Its simplicity is why nearly every REST API, many configuration files and countless log pipelines use it.
Machines do not care about whitespace, so JSON sent over the network is often minified onto a single line. That is efficient but almost impossible for a person to read. Formatting adds line breaks and consistent indentation so you can see the nesting at a glance, spot a missing field, and compare two documents in a diff. Minifying does the opposite and is useful when you want to embed JSON in a request or reduce payload size.
Common JSON errors and how to fix them
JSON is stricter than JavaScript object literals. These are the mistakes the validator catches most often:
| Problem | Invalid | Valid |
|---|---|---|
| Trailing comma | [1, 2, 3,] | [1, 2, 3] |
| Single quotes | {'name': 'Ada'} | {"name": "Ada"} |
| Unquoted key | {name: "Ada"} | {"name": "Ada"} |
| Comments | // note or /* note */ | Remove them, or use a "_comment" field |
| Non-JSON values | undefined, NaN, Infinity | null or a string |
| Leading zeros | {"id": 007} | {"id": 7} or "007" |
A typical broken snippet copied from JavaScript code looks like this:
{
name: 'Ada Lovelace',
born: 1815, // year
languages: ['English', 'French',],
}
The corrected JSON quotes every key and string with double quotes, drops the comment and removes both trailing commas:
{
"name": "Ada Lovelace",
"born": 1815,
"languages": ["English", "French"]
}
Other frequent causes are unescaped double quotes or raw line breaks inside strings (use \" and \n), and a stray character after the closing bracket. When the reported position looks wrong, check the line just above it: a missing comma is usually only detected when the parser reaches the next value.
Tips and best practices
- Pick one indentation and keep it. Two spaces is the most common convention in JavaScript projects; four spaces is common in Python tooling. Consistency matters more than the choice.
- Sort keys before diffing. JSON objects are unordered, so two equivalent documents can look different. Sorting keys makes version-control diffs and comparisons far cleaner.
- Watch very large numbers. JavaScript stores numbers as 64-bit floating point, so integers larger than 9,007,199,254,740,991 (253 − 1) can lose precision when parsed in a browser. Send big IDs as strings.
- Use UTF-8. RFC 8259 requires UTF-8 for JSON exchanged between systems.
- Convert when it helps. CSV suits a flat array of objects you want to open in a spreadsheet; YAML is easier to hand-edit. For two-way conversion, try the JSON ↔ YAML converter or the CSV ↔ JSON converter.
Frequently asked questions
Does JSON allow comments?
No. Neither RFC 8259 nor ECMA-404 permits comments. Some tools accept extended formats such as JSONC or JSON5, but a standard parser will reject them. Remove comments before validating, or move notes into a regular field.
Why is my JSON invalid when it works in JavaScript?
JavaScript object literals allow single quotes, unquoted keys, trailing commas, comments and values like undefined. JSON allows none of these. Use JSON.stringify() in code to produce valid JSON instead of writing it by hand.
Does formatting change my data?
Formatting and minifying only change whitespace between tokens; keys, values and array order stay the same. Sorting keys reorders object members, which does not change meaning because JSON objects are unordered.
What is the difference between formatting and validating?
Validating checks that the text is syntactically correct JSON. Formatting re-prints valid JSON with readable indentation. The formatter validates first, so you cannot format a document that does not parse.
Can I convert nested JSON to CSV?
CSV is a flat table, so it works best with an array of objects that share the same keys. Nested objects and arrays have no direct CSV equivalent and are typically flattened or serialised into a single cell.