JSON Formatting & Validation: A Developer's Complete Reference
5 min read · Updated June 2026
JSON (JavaScript Object Notation) is the lingua franca of modern APIs and configuration files. But malformed JSON is one of the most common sources of bugs. This guide covers the most frequent errors, validation strategies, and tools to keep your JSON clean.
The 5 Most Common JSON Errors
- Trailing commas —
{"a": 1,}is invalid. JSON does not allow trailing commas after the last item in an object or array. - Single quotes —
{'a': 1}is invalid. JSON requires double quotes for strings and keys. - Unquoted keys —
{a: 1}is invalid. All keys must be in double quotes. - Comments —
// commentand/* comment */are not valid JSON. Use JSONC or JSON5 if you need comments. - Special characters — Unescaped newlines, tabs, or control characters in strings break parsing.
JSON Data Types
JSON supports exactly 6 data types:
- String:
"hello"(double-quoted) - Number:
42,3.14,-1,1.5e10(no leading zeros except 0.x) - Boolean:
trueorfalse(lowercase) - Null:
null(lowercase) - Array:
[1, 2, 3](ordered, can mix types) - Object:
{"key": "value"}(unordered key-value pairs)
Format and Validate JSON Instantly
Use our JSON Formatter to validate, beautify, and minify JSON with detailed error messages pointing to the exact line and column.
Best Practices for Writing JSON
- Always use a linter or formatter — never hand-write large JSON files
- Use consistent indentation (2 spaces is the standard)
- Sort keys alphabetically for easier diffing in version control
- Use schemas (JSON Schema) to validate structure, not just syntax
- Keep files under 10MB — split large datasets into multiple files
JSON vs JSON5 vs JSONC vs YAML
| Feature | JSON | JSON5 | JSONC | YAML |
|---|---|---|---|---|
| Comments | No | Yes | Yes | Yes |
| Trailing commas | No | Yes | No | N/A |
| Unquoted keys | No | Yes | No | Yes |
| Multi-line strings | No | Yes | No | Yes |
| Strict spec | Yes | No | Partial | Complex |
Converting Between JSON and CSV
Many data workflows require converting between JSON and CSV formats. Common pitfalls include:
- Nested objects don't flatten automatically — you need to decide how to handle them
- CSV has no type system — all values become strings
- Character encoding issues (UTF-8 BOM, special characters)
Convert CSV to JSON (and Back)
Our CSV ↔ JSON Converter handles delimiters, nested objects, and encoding automatically.
The Bottom Line
- Always validate JSON before using it — syntax errors cause silent failures
- The 5 most common errors are: trailing commas, single quotes, unquoted keys, comments, and special characters
- Use tools to format and validate — don't rely on manual inspection
- Consider JSON Schema for structural validation beyond syntax
- Know when to use alternatives like JSON5 or YAML for configuration files