HOW IT WORKS
Format (beautify) • Minify (compact) • Auto-validate on paste. Perfect for debugging APIs and config files.
WHAT IS JSON?
JSON (JavaScript Object Notation): A lightweight data format for storing and exchanging structured information. Originally derived from JavaScript but now language-independent - used by Python, Java, C#, PHP, and virtually all programming languages.
Basic Structure: Data is organized as key-value pairs. Example: {"name": "Alice", "age": 25, "active": true}. Keys must be strings in double quotes. Values can be strings, numbers, booleans (true/false), arrays [], objects {}, or null.
Why JSON? Human-readable (unlike binary formats), easy to parse (unlike XML with complex syntax), universally supported, and compact enough for network transmission. It's the de facto standard for web APIs.
JSON vs XML: JSON is simpler and more compact. Example: JSON {"name": "Bob"} vs XML <person><name>Bob</name></person>. JSON is typically 20-30% smaller and faster to parse.
COMMON JSON USE CASES
REST APIs: Most web APIs (Twitter, GitHub, Google, Stripe) return data in JSON. Your browser/app sends a request, receives JSON response, parses it, and displays data. Example: Weather apps fetch JSON from weather APIs.
Configuration Files: Modern tools use JSON configs: package.json (Node.js dependencies), tsconfig.json (TypeScript settings), .eslintrc.json (code linting rules), VS Code settings.json. Easier than old-style .ini or .conf files.
Data Storage: NoSQL databases (MongoDB, CouchDB, Firebase) store data as JSON-like documents. Each record is a JSON object with flexible schema - no need to define columns like SQL.
Data Exchange: Microservices communicate via JSON over HTTP. Mobile apps sync JSON data to cloud. ETL pipelines export/import JSON between systems. It's the universal data exchange format.
COMMON JSON VALIDATION ERRORS
Trailing commas: {"a": 1, "b": 2,} - Last item can't have comma. JSON spec is stricter than JavaScript.
Single quotes: {'name': 'Alice'} - Must use double quotes for strings. Single quotes are invalid in JSON (though valid in JavaScript).
Unquoted keys: {name: "Alice"} - Keys must be quoted: {"name": "Alice"}. Again, stricter than JavaScript objects.
Comments not allowed: JSON doesn't support comments (// or /* */). If you need comments, use a "_comment" key: {"_comment": "This is a note", "data": 123}.
Undefined/NaN/Infinity: JSON only supports null, not JavaScript's undefined/NaN/Infinity. Convert these to null or string representations before stringifying.
JSON BEST PRACTICES
Formatting for readability: Use formatted (pretty-printed) JSON during development with 2-space indentation. Use minified JSON for production/APIs to save bandwidth (can reduce size by 20-40%).
Consistent key naming: Use camelCase (firstName, lastName) or snake_case (first_name, last_name) consistently. Most JavaScript/TypeScript projects prefer camelCase. Python/Ruby often use snake_case.
Avoid deeply nested structures: JSON parsers can handle deep nesting, but it's harder to read and query. Flatten where possible. Instead of {"user": {"profile": {"address": {"city": "NYC"}}}}, consider {"userCity": "NYC"} if that level of structure isn't needed.
Security: Validate untrusted JSON: Never use eval() to parse JSON - it can execute malicious code. Always use JSON.parse() (JavaScript) or equivalent safe parsers in other languages. Validate structure/types after parsing before using data.