What Is JSON? A Developer's Complete Guide to Formatting, Validating & Debugging JSON in 2026
Everything developers need to know about JSON: syntax rules, common errors, API best practices, performance tips, JSON Schema, and online formatting tools.
DedevTool
What Is JSON? A Developer's Complete Guide to Formatting, Validating & Debugging JSON in 2026
If you're a developer – frontend, backend, mobile, or data – you work with JSON every single day. But do you truly understand it? Do you know why a trailing comma crashes your API? Or why JSON.parse("") throws instead of returning null?
This isn't a beginner "what is JSON" tutorial. This is everything a working developer needs to handle JSON efficiently in production systems.
1. What Is JSON?
JSON (JavaScript Object Notation) is a text-based data format used to exchange data between clients, servers, and systems.
{
"name": "John Doe",
"age": 28,
"email": "john@example.com",
"isActive": true,
"skills": ["JavaScript", "Python", "Go"],
"address": {
"city": "San Francisco",
"country": "USA"
}
}
Why JSON Beat XML
| Criteria | JSON | XML |
|---|---|---|
| Syntax | Concise, readable | Verbose, tag-heavy |
| Payload size | ~30–50% smaller | Larger |
| Parse speed | Fast (native JS) | Slower |
| Language support | Universal | Universal |
| Year introduced | 2001 (Crockford) | 1996 |
JSON is smaller, faster, and more readable. That's why 99% of modern REST APIs use JSON over XML.
2. JSON Syntax – 7 Rules That Will Save You Hours of Debugging
Rule 1: Keys MUST be double-quoted strings
// ✅ Valid
{ "name": "value" }
// ❌ Invalid - unquoted key
{ name: "value" }
// ❌ Invalid - single quotes
{ 'name': 'value' }
Rule 2: Strings MUST use double quotes (not single)
// ✅ Valid
{ "city": "New York" }
// ❌ Invalid
{ "city": 'New York' }
Rule 3: No trailing commas
// ✅ Valid
{ "a": 1, "b": 2 }
// ❌ Invalid - trailing comma after last item
{ "a": 1, "b": 2, }
This is the most common JSON error. JavaScript allows trailing commas; JSON does NOT.
Rule 4: Only 6 data types exist
| Type | Example |
|---|---|
| String | "hello" |
| Number | 42, 3.14, -1, 1e10 |
| Boolean | true, false |
| Null | null |
| Object | { "key": "value" } |
| Array | [1, 2, 3] |
Not supported: undefined, NaN, Infinity, Date, RegExp, comments, functions.
Rule 5: No comments allowed
// ❌ JSON does not support comments
{
"name": "value" // This causes a parse error
}
For config files that need comments, use JSON5 or JSONC (supported by VS Code).
Rule 6: No leading zeros on numbers
// ✅ Valid
{ "price": 0.5 }
// ❌ Invalid
{ "price": 00.5 }
{ "id": 007 }
Rule 7: Special characters require escaping
{ "tab": "col1\tcol2" }
{ "newline": "line1\nline2" }
{ "quote": "He said \"hello\"" }
{ "unicode": "\u2764" }
Format and validate JSON instantly: 👉 JSON Formatter & Validator
3. Common JSON Errors and How to Fix Them
Error 1: "Unexpected token"
Cause: Trailing comma, missing quotes, or invalid character.
// ❌ Broken
{
"items": [1, 2, 3,],
"status": active
}
// ✅ Fixed
{
"items": [1, 2, 3],
"status": "active"
}
Error 2: "Unexpected end of JSON input"
Cause: Missing closing bracket/brace, or empty string input.
// ❌ Crash
JSON.parse("")
// ✅ Fix - guard the input
const data = input ? JSON.parse(input) : {};
Error 3: Circular reference during serialization
const a = {};
const b = { ref: a };
a.ref = b;
// ❌ TypeError: Converting circular structure to JSON
JSON.stringify(a);
// ✅ Fix with replacer function
JSON.stringify(a, (key, value) => {
if (key === 'ref') return '[Circular]';
return value;
});
Error 4: Date objects become strings
const data = { created: new Date() };
const json = JSON.stringify(data);
// {"created":"2026-04-19T10:30:00.000Z"}
const parsed = JSON.parse(json);
parsed.created instanceof Date; // false! It's a string now
// ✅ Fix with reviver function
const parsed2 = JSON.parse(json, (key, value) => {
if (key === 'created') return new Date(value);
return value;
});
4. JSON in API Design – Best Practices 2026
Standard Response Format
// ✅ Success response
{
"status": "success",
"data": {
"users": [
{ "id": 1, "name": "Alice Johnson" },
{ "id": 2, "name": "Bob Smith" }
],
"total": 2,
"page": 1,
"perPage": 20
}
}
// ✅ Error response
{
"status": "error",
"error": {
"code": "VALIDATION_ERROR",
"message": "Email is required",
"details": [
{ "field": "email", "message": "Must be a valid email address" }
]
}
}
Naming Conventions
| Convention | Example | Used In |
|---|---|---|
| camelCase | firstName, createdAt | JavaScript, TypeScript, Java |
| snake_case | first_name, created_at | Python, Ruby, PostgreSQL |
| PascalCase | FirstName | C#, .NET |
| kebab-case | first-name | ❌ Don't use in JSON |
Rule: Pick one convention and use it consistently across your entire API. Don't mix firstName and last_name in the same response.
5. JSON vs Other Data Formats
| Format | When to Use | Key Advantage |
|---|---|---|
| JSON | APIs, simple config | Universal, native JS |
| YAML | Complex config (Docker, K8s) | Readable, supports comments |
| TOML | Config (Rust, Python) | Clear, no indent ambiguity |
| Protocol Buffers | gRPC, high-performance | 3–10x smaller, 20–100x faster than JSON |
| MessagePack | Cache, WebSocket | Binary, ~30% smaller than JSON |
| CSV | Tabular data export | Excel-friendly |
6. JSON Formatting Operations
Pretty-Print (Format)
Convert one-line API output into readable format:
Before:
{"user":{"id":1,"name":"Test","roles":["admin","editor"],"settings":{"lang":"en","theme":"dark"}}}
After:
{
"user": {
"id": 1,
"name": "Test",
"roles": ["admin", "editor"],
"settings": {
"lang": "en",
"theme": "dark"
}
}
}
Minify (Compress)
Remove all whitespace to reduce payload size by 30–50%. Useful for:
- Database storage
- WebSocket messages
- API bandwidth optimization
Validate
Check JSON correctness before deploying. A single trailing comma in a production config file can crash your entire service.
All operations in one tool: 👉 JSON Formatter, Validator & Minifier
7. JSON Schema – Type Safety for JSON
JSON Schema enables automatic structure validation:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"email": { "type": "string", "format": "email" }
},
"required": ["name", "email"]
}
JSON Schema use cases:
- API request body validation
- Config file validation in CI/CD pipelines
- OpenAPI (Swagger) specification
- React Hook Form + Zod (compiles to JSON Schema)
8. Performance Tips for Large JSON
Parsing large JSON → Use streaming
JSON.parse() blocks the event loop for files > 50–100MB. Use streaming parsers:
// Node.js streaming JSON parse
import { parser } from 'stream-json';
import { streamArray } from 'stream-json/streamers/StreamArray';
fs.createReadStream('huge-file.json')
.pipe(parser())
.pipe(streamArray())
.on('data', ({ value }) => processItem(value));
Faster serialization with schema
fast-json-stringify is 2–10x faster than JSON.stringify() when you know the schema:
import fastJson from 'fast-json-stringify';
const stringify = fastJson({
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'integer' }
}
});
stringify({ name: 'Test', age: 28 }); // 2-10x faster
Compression for network transfer
Use gzip/brotli compression for JSON API responses. A typical JSON payload compresses by 60–80%:
- 100 KB JSON → ~25 KB gzipped
- Most browsers and HTTP clients handle decompression automatically
9. FAQ
Is JSON the same as a JavaScript Object?
Similar but NOT identical. JavaScript Objects allow: trailing commas, unquoted keys, single quotes, undefined, functions, Symbols. JSON allows none of these.
How do I add comments to JSON?
Use JSONC (rename to .jsonc) or JSON5. VS Code's settings.json is actually JSONC behind the scenes.
What's the maximum JSON size?
The spec has no limit. In practice, V8 (Chrome/Node.js) handles up to ~500MB comfortably. Real limits are set by your server (Nginx default: 1MB body, Express default: 100KB).
Why does my API return null instead of my data?
Common causes:
Content-Typeheader isn't set toapplication/json- Response body isn't valid JSON (try pasting it into a validator)
- Server returned an empty response, which your client parsed to
null
Free Online JSON Tool
Format, validate, and minify JSON in one click – no installation, no sign-up: