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. Despite its name, JSON is language-independent and is used across virtually every programming language.
JSON Syntax Rules
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
- Strings must use double quotes
A Simple JSON Example
{
"name": "John Doe",
"age": 30,
"isActive": true,
"tags": ["developer", "designer"]
}JSON Data Types
JSON supports six data types: strings, numbers, objects, arrays, booleans (true/false), and null. This covers the vast majority of data you'll ever need to represent.
Why is JSON So Popular?
JSON replaced XML as the de-facto web data format because it's more compact, easier to read, and maps directly to data structures in nearly every programming language. REST APIs, configuration files, and databases like MongoDB all rely on JSON.
Common JSON Mistakes to Avoid
- Using single quotes instead of double quotes
- Leaving a trailing comma after the last item
- Forgetting quotes around string keys
- Using undefined or functions as values