JSON (JavaScript Object Notation) is the de facto standard for data interchange on the web. Every REST API, every configuration file, every NoSQL database, and every real-time messaging system uses JSON as its primary serialization format. First described by Douglas Crockford in the early 2000s and formally specified in RFC 8259, JSON has achieved universal adoption precisely because of its simplicity — the entire specification fits on a single page, yet it's expressive enough to represent any structured data.
Despite JSON's apparent simplicity, syntax errors are one of the most common sources of bugs in web development. A missing comma, a trailing comma, an unquoted key, a single quote instead of a double quote, or a value of undefined instead of null — each of these will produce invalid JSON that breaks API calls, corrupts data, and causes silent failures. Unlike more forgiving formats, JSON parsers are strict by design: a single syntax error makes the entire document unparseable.
This guide is a comprehensive reference for JSON syntax, covering every valid construct, every data type, every edge case, and every common error pattern. Whether you're learning JSON for the first time, debugging a cryptic parse error, or building systems that generate JSON programmatically, this guide will serve as your definitive reference. We'll also show you how our JSON Formatter can instantly validate, format, and fix JSON syntax issues.
Validate & Format JSON Instantly
Our free JSON Formatter validates syntax, highlights errors with line numbers, and beautifies minified JSON with one click.
Open JSON Formatter →JSON Structure: Objects and Arrays
Every valid JSON document is either an object or an array at its root level. An object is an unordered collection of key-value pairs enclosed in curly braces {}. An array is an ordered list of values enclosed in square brackets []. These two structures can be nested to any depth to represent complex hierarchical data.
Objects
A JSON object consists of zero or more key-value pairs, where each key is a double-quoted string and each value is any valid JSON type. Pairs are separated by commas. The key and value within each pair are separated by a colon.
{
"name": "Alice Chen",
"age": 28,
"email": "alice@example.com",
"isActive": true,
"address": null
}Arrays
A JSON array is an ordered sequence of values, separated by commas. Array elements can be any valid JSON type — strings, numbers, booleans, null, objects, or other arrays. Elements in an array don't need to be the same type (though mixing types is unusual in practice).
{
"colors": ["red", "green", "blue"],
"matrix": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
"mixed": ["text", 42, true, null, {"key": "value"}]
}JSON Data Types
JSON supports exactly six data types. Understanding the precise syntax rules for each type is essential for avoiding parse errors:
| Type | Syntax | Examples | Common Errors |
|---|---|---|---|
| String | Double-quoted text | "hello", "line\nbreak" |
Single quotes 'hello' |
| Number | Integer or float | 42, -3.14, 2.5e10 |
Leading zeros 07, hex 0xFF |
| Boolean | Lowercase true/false | true, false |
Capitalized True, FALSE |
| Null | Lowercase null | null |
None, NULL, undefined |
| Object | Curly braces | {"key": "value"} |
Unquoted keys {key: "value"} |
| Array | Square brackets | [1, 2, 3] |
Trailing comma [1, 2, 3,] |
String Escaping Rules
JSON strings must be enclosed in double quotes (never single quotes). Within a string, certain characters must be escaped with a backslash. Failing to escape these characters— or escaping characters that don't need it — is a frequent source of parse errors.
| Escape Sequence | Character | Example |
|---|---|---|
\" |
Double quote | "She said \"hello\"" |
\\ |
Backslash | "C:\\Users\\alice" |
\n |
Newline | "line 1\nline 2" |
\t |
Tab | "col1\tcol2" |
\r |
Carriage return | "text\r\n" |
\b |
Backspace | Rarely used |
\f |
Form feed | Rarely used |
\uXXXX |
Unicode character | "\u00E9" → é |
\n, \t). A string with a literal line break will cause a parse error — the line break must be represented as \n within the quoted string.
The 10 Most Common JSON Syntax Errors
These are the errors we see most frequently in our JSON Formatter tool, ranked by frequency. Most are simple typos that are easy to fix once identified:
| # | Error | Invalid | Valid |
|---|---|---|---|
| 1 | Trailing comma | {"a":1, "b":2,} |
{"a":1, "b":2} |
| 2 | Single quotes | {'key': 'value'} |
{"key": "value"} |
| 3 | Unquoted keys | {key: "value"} |
{"key": "value"} |
| 4 | Missing comma between pairs | {"a":1 "b":2} |
{"a":1, "b":2} |
| 5 | Using undefined | {"a": undefined} |
{"a": null} |
| 6 | Comments in JSON | {"a": 1} // comment |
{"a": 1} |
| 7 | Unescaped special characters | {"path": "C:\new"} |
{"path": "C:\\new"} |
| 8 | Leading zeros in numbers | {"zip": 07501} |
{"zip": "07501"} |
| 9 | NaN / Infinity | {"value": NaN} |
{"value": null} |
| 10 | Capitalized boolean/null | {"active": True} |
{"active": true} |
JSON in Practice: Common Patterns
Here are the JSON patterns you'll encounter most frequently in real-world API development and data modeling:
API Response Envelope
{
"status": "success",
"data": {
"users": [
{
"id": 1,
"name": "Alice",
"email": "alice@example.com",
"roles": ["admin", "editor"]
},
{
"id": 2,
"name": "Bob",
"email": "bob@example.com",
"roles": ["viewer"]
}
],
"pagination": {
"page": 1,
"perPage": 20,
"total": 150,
"totalPages": 8
}
},
"meta": {
"requestId": "abc-123-def",
"timestamp": "2026-03-11T16:00:00Z"
}
}Configuration File Pattern
{
"app": {
"name": "MyApp",
"version": "2.1.0",
"debug": false
},
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp_production",
"ssl": true,
"pool": {
"min": 5,
"max": 20
}
},
"features": {
"darkMode": true,
"experimentalSearch": false,
"maxUploadSize": 10485760
}
}JSON vs JavaScript Object Literals
Because JSON evolved from JavaScript, the two formats look similar but have critical differences. Code that works as a JavaScript object literal will often be invalid JSON. Here are the key differences:
| Feature | JavaScript Object | JSON |
|---|---|---|
| Key quoting | Optional (unquoted allowed) | Required (double quotes only) |
| String quotes | Single or double | Double only |
| Trailing commas | Allowed | Not allowed |
| Comments | // and /* */ | Not allowed |
| undefined | Valid value | Not allowed (use null) |
| Functions | Valid value | Not allowed |
| NaN / Infinity | Valid numbers | Not allowed |
Character Encoding: The UTF-8 Mandate
The JSON specification (RFC 8259) explicitly mandates that JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8. While previous specifications allowed for UTF-16 and UTF-32, the modern standard has unified around UTF-8 to prevent parsing ambiguities and security vulnerabilities.
If your backend transmits a JSON payload encoded in ISO-8859-1 (Latin-1) or Windows-1252 to a frontend application expecting UTF-8, any special characters (like accents or emojis) will be corrupted, and strictly compliant parsers will immediately throw a fatal error. Always explicitly set the HTTP header Content-Type: application/json; charset=utf-8 when serving JSON over the network.
Parsing and Performance Considerations
While JSON is text, computing systems must parse that text into memory structures (Object models) before they can interact with the data. The speed at which a language can parse JSON directly impacts application performance, especially in heavy API environments.
- JavaScript (V8/Node.js):
JSON.parse()is heavily optimized at the C++ level. However, a little-known optimization is that parsing a large JSON string is often significantly faster than parsing the equivalent JavaScript object literal embedded directly in the source code. This is why tools like Webpack sometimes wrap configuration objects insideJSON.parse("...")during bundling. - Python: The native
json.loads()is sufficient for normal use, but for high-throughput microservices, developers typically swap the standard library for C-compiled alternatives likeorjsonorujson, which can be up to 10x faster. - Go: Go's standard
encoding/jsonuses reflection, which is slow. High-performance Go applications often use code-generation tools (likeeasyjson) to generate static parsers at compile time, bypassing reflection entirely.
Handling Massive Datasets: NDJSON and Streaming
Standard JSON has a fatal flaw when dealing with massive datasets (e.g., millions of log entries or multi-gigabyte database exports): the entire document must be loaded into RAM before the parser can begin reading it. A standard array `[ {id:1}, {id:2}, ... ]` cannot be processed until the final closing bracket `]` is reached.
To solve this memory bottleneck, the industry developed NDJSON (Newline Delimited JSON), also known as JSON Lines.
{"id": 1, "level": "INFO", "message": "Server started"}
{"id": 2, "level": "WARN", "message": "High CPU load"}
{"id": 3, "level": "ERROR", "message": "Database disconnected"}In NDJSON, the document is not a single valid JSON array. Instead, every single line is an independent, valid JSON object, separated by a newline character (\n). This allows the receiving application to stream the file, parsing (and then discarding from memory) one object at a time. Total memory consumption stays flat, regardless of whether the file is 10 Megabytes or 10 Terabytes.
Payload Size Limits and Security Vectors
JSON parsers are historically vulnerable to specific types of Denial of Service (DoS) attacks. Because arrays and objects can be nested infinitely, a malicious actor can send a tiny JSON payload consisting of 100,000 nested opening braces {{{{{.... When the server attempts to parse this, it exceeds the call stack limit and crashes the process.
Defensive Architecture:
- Max Payload Size: Always configure your web framework to reject JSON bodies larger than your expected maximum (e.g., 1MB or 5MB). In Express.js, this is done via
app.use(express.json({ limit: '1mb' })). - Max Nesting Depth: Configure your JSON parser to abort if the object nesting goes deeper than a reasonable limit (e.g., 20 or 50 levels). Deeply nested JSON is almost always an architectural flaw or a deliberate attack.
Validate Your JSON Now
Paste any JSON into our formatter to instantly check for syntax errors and get clean, readable output.
Open JSON Formatter →Frequently Asked Questions
What is JSON?
What are the valid data types in JSON?
true/false), null, objects ({}), and arrays ([]). No functions, undefined, dates, or comments.
Does JSON support comments?
What is the difference between JSON and a JavaScript object?
undefined or functions. JavaScript objects allow all of these. Always validate JSON separately from JavaScript object syntax.
How do I validate JSON syntax?
JSON.parse() (JavaScript), json.loads() (Python), or JsonParser (Java) — all throw errors on invalid syntax.
Related Resources
- JSON to CSV Converter — Try it free on DominateTools
- JSON vs XML vs YAML — Format comparison guide
- Debug JSON API Responses — API troubleshooting techniques
- JSON Schema Validation — Enforce data structure rules
- JSON Best Practices — Design and performance tips
- Free JSON Formatter — Validate and beautify JSON