JSON: The Universal Data Format
JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate. It has become the de facto standard for data exchange in web applications, APIs, configuration files, and more.
JSON Syntax Basics
{
"string": "Hello World",
"number": 42,
"float": 3.14,
"boolean": true,
"null": null,
"array": [1, 2, 3],
"object": {
"nested": "value"
}
}JSON Data Types
String
Text enclosed in double quotes: "hello"
Number
Integer or floating-point: 42, 3.14
Boolean
True or false: true, false
Null
Empty value: null
Array
Ordered list: [1, 2, 3]
Object
Key-value pairs: {"key": "value"}
Common JSON Errors
Trailing Commas
JSON doesn't allow trailing commas after the last element: {"a": 1,} is invalid.
Single Quotes
Only double quotes are valid: 'hello' should be "hello"
Unquoted Keys
Object keys must be quoted: {key: "value"} should be {"key": "value"}
Comments
JSON doesn't support comments. Remove // or /* */ before parsing.
Format vs Minify
Format / Beautify
Adds proper indentation and line breaks for readability. Use during development and debugging.
Minify
Removes all unnecessary whitespace to reduce file size. Use for production to save bandwidth.
JSON vs Other Formats
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Readability | Good | Moderate | Excellent |
| File Size | Small | Large | Small |
| Comments | No | Yes | Yes |
| Browser Support | Native | Parser needed | Parser needed |
FAQ
Why is my JSON invalid?
Common issues include trailing commas, single quotes, unquoted keys, or comments. Use this validator to find the exact error location.
Can JSON contain functions?
No, JSON is purely a data format. It cannot contain functions, dates (use strings), or undefined values.
What's the difference between JSON and JavaScript objects?
JSON is a text format. JavaScript objects can contain functions and don't require quoted keys. JSON is a subset of JavaScript object notation.
Is there a maximum size for JSON?
JSON itself has no size limit, but browsers and servers have practical limits. Very large JSON should be paginated or streamed.