What is JSON and Why Does Formatting Matter?
JSON (JavaScript Object Notation) is the de facto standard for data exchange on the web. Every REST API, modern database, and configuration file uses JSON. When you're debugging APIs or reading logs, raw JSON can look like this:
{"name":"Rahul","age":28,"skills":["JavaScript","React","Node.js"],"address":{"city":"Mumbai","state":"Maharashtra"}}
Not very readable. A formatted version with proper indentation makes it much easier to understand your data structure and spot errors quickly.
Common JSON Errors and How to Fix Them
1. Trailing Commas
JSON does NOT allow trailing commas (unlike JavaScript). This is one of the most common mistakes:
// Invalid JSON
{"name": "Priya", "city": "Delhi",} โ trailing comma error
// Valid JSON
{"name": "Priya", "city": "Delhi"}
2. Single Quotes Instead of Double Quotes
JSON requires double quotes for all strings and keys. Single quotes cause parse errors:
// Invalid
{'name': 'Rahul'}
// Valid
{"name": "Rahul"}
3. Unquoted Keys
// Invalid
{name: "Amit"}
// Valid
{"name": "Amit"}
4. Undefined, NaN, or Infinity Values
These are JavaScript concepts that don't exist in JSON. Use null for missing values instead.
JSON Schema: Validate Your Structure
If you're building APIs, defining a JSON Schema helps validate incoming data. For example, a schema requiring a name (string) and age (number) between 18-100 will reject invalid payloads automatically.
When to Minify JSON
Minifying removes all whitespace from JSON, making files smaller for production. This reduces bandwidth costs for APIs:
- Formatted JSON (100 objects): ~12 KB
- Minified JSON (same data): ~8 KB โ 33% smaller
Always minify JSON in production, but keep it human-readable during development.
Use the Free ToolDost JSON Formatter
The ToolDost JSON Formatter lets you:
- Format/Pretty Print: Convert compressed JSON to readable indented format
- Validate: Check for JSON syntax errors instantly
- Minify: Compress JSON by removing whitespace
- Copy to clipboard: One-click copy for your code
Other Developer Tools
- Base64 Encoder/Decoder โ Encode binary data as text
- UUID Generator โ Generate unique identifiers for databases
- URL Encoder/Decoder โ Encode/decode URL parameters
- Regex Tester โ Test regular expressions live
- Timestamp Converter โ Convert Unix timestamps to human dates
- Color Converter โ HEX, RGB, HSL conversions
Topics Covered