Quick reference guide for JSON syntax, methods, and best practices
{
"string": "value",
"number": 42,
"float": 3.14,
"boolean": true,
"null": null,
"array": [1, 2, 3],
"object": {"nested": true}
}
"string" - Text in double quotes123 - Number (int or float)true/false - Booleannull - Null value[] - Array{} - Object// Example
{
"name": "John", // string
"age": 30, // number
"active": true, // boolean
"spouse": null, // null
"hobbies": [], // array
"address": {} // object
}
// Simple array
[1, 2, 3, 4, 5]
// Mixed types
["text", 123, true, null]
// Array of objects
[
{"id": 1, "name": "John"},
{"id": 2, "name": "Jane"}
]
// Nested arrays
[[1, 2], [3, 4]]
// Simple object
{"key": "value"}
// Nested object
{
"user": {
"name": "John",
"address": {
"city": "NYC"
}
}
}
// Object with array
{
"users": [
{"id": 1},
{"id": 2}
]
}
// Parse JSON string const obj = JSON.parse(jsonString); // Convert to JSON string const str = JSON.stringify(obj); // Pretty print (2-space indent) JSON.stringify(obj, null, 2); // With replacer function JSON.stringify(obj, (k, v) => k === 'password' ? undefined : v ); // Parse with reviver JSON.parse(str, (k, v) => k === 'date' ? new Date(v) : v );
'value'"value"{"a": 1,}{"a": 1}{key: "value"}{"key": "value"}// comment\" - Double quote\\ - Backslash\/ - Forward slash\n - Newline\r - Carriage return\t - Tab\b - Backspace\f - Form feed\uXXXX - Unicode"He said \"Hello\"" "Path: C:\\Users\\Name" "Line 1\nLine 2"
200 OK - Success201 Created - Resource created204 No Content - Success, no body400 Bad Request - Invalid JSON401 Unauthorized - Auth required404 Not Found - Not found422 Unprocessable - Validation fail500 Server Error - Server issue// Request
Content-Type: application/json
Accept: application/json
// Response
Content-Type: application/json
Cache-Control: max-age=3600
// Fetch example
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
$ - Root element@ - Current element. - Child element.. - Recursive descent* - Wildcard[] - Array subscript[,] - Union operator[?()] - Filter expression$.store.book[0].title $.store.book[*].author $..author $.store.book[?(@.price < 10)]
30+ professional tools for all your JSON needs