Getting Started
3 snippetsJSON basics and syntax rules
Basic Structure
{
"key": "value"
} Comments
// JSON does NOT support comments
// Use JSDoc or remove before parsing Key Rules
// Keys MUST be quoted strings
{
"name": "valid",
name: "invalid"
} Data Types
5 snippetsSupported value types
String
{
"name": "John",
"city": "New York"
} Number
{
"age": 30,
"price": 19.99,
"negative": -5,
"scientific": 1.2e+3
} Boolean
{
"isActive": true,
"isDeleted": false
} Null
{
"value": null
} No Undefined
// JSON does NOT support undefined
// Use null instead Arrays
5 snippetsOrdered lists of values
Simple Array
{
"fruits": ["apple", "banana", "orange"]
} Mixed Types
{
"mixed": [1, "two", true, null]
} Nested Arrays
{
"matrix": [
[1, 2, 3],
[4, 5, 6]
]
} Array of Objects
{
"users": [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 30}
]
} Empty Array
{
"items": []
} Tired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Objects
4 snippetsKey-value pairs
Simple Object
{
"person": {
"name": "John",
"age": 30
}
} Nested Objects
{
"user": {
"profile": {
"name": "John",
"address": {
"city": "NYC"
}
}
}
} Empty Object
{
"config": {}
} Object with Arrays
{
"person": {
"name": "John",
"hobbies": ["reading", "coding"]
}
} Special Characters
3 snippetsEscaping and Unicode
Escape Sequences
{
"quote": "\"Hello\"",
"backslash": "\\",
"newline": "Line 1\nLine 2",
"tab": "Col1\tCol2"
} Unicode
{
"unicode": "\u0041",
"emoji": "\uD83D\uDE00"
} Valid Escapes
\" \\ \/ \b \f \n \r \t \uXXXX Formatting
3 snippetsReadable vs compact
Pretty Printed
{
"name": "John",
"age": 30,
"hobbies": [
"reading",
"coding"
]
} Compact (Minified)
{"name":"John","age":30,"hobbies":["reading","coding"]} No Trailing Commas
// Invalid:
{
"a": 1,
"b": 2,
}
// Valid:
{
"a": 1,
"b": 2
} Common Patterns
4 snippetsReal-world usage examples
API Response
{
"status": "success",
"data": {
"id": 1,
"name": "Product"
},
"message": "Retrieved"
} Config File
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"port": 3000
}
} Package.json
{
"name": "my-package",
"version": "1.0.0",
"dependencies": {
"express": "^4.18.0"
}
} Error Response
{
"error": {
"code": 404,
"message": "Not Found",
"details": []
}
} Limitations
5 snippetsWhat JSON cannot do
No Comments
// Cannot include comments in JSON
// Remove before parsing No Functions
// Cannot include functions
{
"invalid": function() {}
} No Dates
// No native date type
{
"date": "2024-01-01T00:00:00Z"
} No Undefined/NaN/Infinity
// Use null instead
{
"value": null
} No Trailing Commas
// Last item cannot have comma
{
"a": 1 // OK
}