JSON Cheatsheet
A quick reference guide for JSON syntax, data types, and common patterns.
๐ Basic Syntax
{ }Object - key-value pairs
[ ]Array - ordered list
" "String - double quotes only
:Separates key from value
,Separates items (no trailing comma!)
๐ค Data Types
| String | "hello" |
| Number | 42, 3.14, -17, 2e10 |
| Boolean | true, false |
| Null | null |
| Array | [1, 2, 3] |
| Object | {"key": "value"} |
๐ก Escape Sequences
\"Quote
\\Backslash
\nNewline
\tTab
\rCarriage return
\uXXXXUnicode
๐ซ Not Allowed in JSON
โ
'single quotes'Use double quotesโ
// commentsNo commentsโ
[1, 2, 3,]No trailing commaโ
undefinedUse null insteadโ
{key: "value"}Keys must be quoted๐ฆ Object Example
{
"name": "John Doe",
"age": 30,
"isActive": true,
"email": null,
"tags": ["developer", "writer"],
"address": {
"city": "Istanbul",
"country": "Turkey"
}
}๐ Array Examples
Strings
["apple", "banana", "cherry"]
Numbers
[1, 2, 3, 4, 5]
Objects
[{"id": 1}, {"id": 2}]Mixed
["text", 42, true, null]
๐ป JavaScript Methods
JSON.parse()
// String โ Object
const obj = JSON.parse('{"a":1}');
// obj.a === 1JSON.stringify()
// Object โ String
const str = JSON.stringify({a:1});
// str === '{"a":1}'Pretty Print
JSON.stringify(obj, null, 2); // 2-space indentation
Reviver Function
JSON.parse(str, (k, v) => {
if (k === 'date') return new Date(v);
return v;
});๐ฏ Common Patterns
API Response
{
"data": [...],
"meta": {
"total": 100,
"page": 1
}
}Config File
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"build": "vite build"
}
}GeoJSON
{
"type": "Point",
"coordinates": [
29.0, 41.0
]
}Ready to work with JSON?