How to use the JSON Formatter
- Paste your JSON into the input panel on the left, or click “Try sample” to load an example.
- See validation instantly — if your JSON has syntax errors, a red border appears on the input and the error message is shown below it. Valid JSON shows a green “✓ Valid” indicator in the stats bar.
- Choose your indent style — switch between 2 spaces, 4 spaces, or tabs using the segmented control in the toolbar. Toggle “Sort Keys” to alphabetically sort all object keys.
- Copy the formatted output — click the Copy button in the output panel header to copy the beautified JSON to your clipboard. Use “Minify” to collapse the JSON back to a single line.
JSON syntax rules
JSON (JavaScript Object Notation) has strict syntax rules. Here is a quick reference:
- ·Keys must be strings wrapped in double quotes — e.g. "name" not name.
- ·String values must use double quotes — single quotes are not valid JSON.
- ·Trailing commas are not allowed — the last item in an object or array must not have a comma.
- ·Numbers are unquoted — e.g. 42 or 3.14.
- ·Booleans are lowercase: true or false.
- ·Null is lowercase: null.
- ·Comments are not supported in standard JSON.
- ·The root value can be an object, array, string, number, boolean, or null.
Need to format YAML too? Try the YAML Formatter.
Common JSON errors and how to fix them
The error messages from JSON.parse() can be cryptic. Here are the most common ones and their causes:
| Error | Cause | Fix |
|---|---|---|
| Unexpected token | Trailing comma after the last item in an object or array | Remove the trailing comma |
| Unexpected token ' | Single quotes used for strings or keys | Replace single quotes with double quotes |
| Unexpected end of JSON input | Missing closing bracket, brace, or quote | Check that all {, [, and " are closed |
| Unexpected token // | JavaScript-style comments in JSON | Remove all comments — JSON does not support them |
| Unexpected token u | Unquoted value like undefined | Use null instead of undefined |
| Expected property name or } | Key not wrapped in double quotes | Wrap all keys in double quotes: "key": value |
| Unexpected number | Number used as a key, or extra comma before a number | Ensure keys are strings; check for duplicate commas |