How to Format and Validate JSON Data
Minified JSON is unreadable and errors are hard to find. Learn how to pretty-print, validate, and transform JSON for debugging and development.
Key Takeaways
- API responses and configuration files often arrive as single-line minified JSON.
- JSON syntax is strict — a single missing comma or extra bracket breaks the entire document.
- Trailing commas**: `{"a": 1,}` — not allowed in JSON (allowed in JS).
- JSON5 and JSONC are supersets that allow comments, trailing commas, and single quotes.
- The reverse of pretty-printing — removing whitespace to minimize file size.
Hash Generator
Generate SHA-1, SHA-256, SHA-384, SHA-512 hashes from text
Why Format JSON?
API responses and configuration files often arrive as single-line minified JSON. Pretty-printing adds indentation and line breaks, making the structure visible and errors easy to spot.
Validation
JSON syntax is strict — a single missing comma or extra bracket breaks the entire document. Validators highlight the exact line and character where parsing fails, saving debugging time.
Common JSON Errors
- Trailing commas:
{"a": 1,}— not allowed in JSON (allowed in JS). - Single quotes:
{'key': 'value'}— JSON requires double quotes. - Unquoted keys:
{key: "value"}— keys must be quoted strings. - Comments:
// comment— JSON doesn't support comments.
JSON vs JSON5 vs JSONC
JSON5 and JSONC are supersets that allow comments, trailing commas, and single quotes. They're used in configuration files (tsconfig.json, VS Code settings) but aren't valid JSON for APIs.
Minification
The reverse of pretty-printing — removing whitespace to minimize file size. Minified JSON is 30-50% smaller than pretty-printed, making it ideal for API responses and storage where human readability isn't needed.
Связанные инструменты
Связанные форматы
Связанные руководства
JSON vs YAML vs TOML: Choosing a Configuration Format
Configuration files are the backbone of modern applications. JSON, YAML, and TOML each offer different trade-offs between readability, complexity, and tooling support that affect your development workflow.
How to Format and Validate JSON Data
Malformed JSON causes silent failures in APIs and configuration files. Learn how to format, validate, and debug JSON documents to prevent integration errors and improve readability.
Base64 Encoding: How It Works and When to Use It
Base64 converts binary data into ASCII text, making it safe for transmission through text-based systems. Learn when Base64 is the right choice and when alternatives like hex encoding or URL encoding are more appropriate.
Best Practices for Working with Unix Timestamps
Unix timestamps provide a language-agnostic way to represent points in time, but they come with pitfalls around time zones, precision, and the 2038 problem. This guide covers best practices for storing and converting timestamps.
Troubleshooting JWT Token Issues
JSON Web Tokens are widely used for authentication but can be frustrating to debug. This guide covers common JWT problems including expiration errors, signature mismatches, and payload decoding issues.