JSON Syntax

What you’ll learn
JSON (JavaScript Object Notation) is a lightweight way to move structured data between systems as plain text. The syntax looks like JavaScript literals, but the grammar is stricter so every parser agrees on the same bytes.
Here you will see the building blocks—braces, brackets, colons, commas, and the six value types—then a full example and how to load it with JSON.parse in the browser.
What is JSON?
JSON is a text-based format built from key–value pairs and ordered lists. Servers send it in HTTP bodies; browsers and runtimes turn it into native types. The formal rules live in RFC 8259; this page is a practical tour of the surface syntax.
Why JSON works well
Lightweight
Fewer delimiters than XML for the same record shape, which keeps payloads smaller.
Language independent
The same UTF‑8 text parses in JavaScript, Python, Go, Rust, and most other stacks.
Structured
Objects and arrays nest cleanly so you can model tables, trees, and documents in one payload.
Easy to parse
Strict grammar means generic parsers (JSON.parse, json.loads, etc.) behave consistently.
JSON syntax rules
Read this checklist once; when something fails validation, one of these rules is usually the culprit.
- Six value types — Every value is a string, number, object, array, boolean, or
null. See the data types page for details and edge cases (for example strict number rules).- String — Unicode text in double quotes, with escapes as needed.
- Number — Decimal digits; optional
-, fraction, and exponent. - Boolean — Literals
trueorfalse(never quoted). - Array —
[ ]around a comma-separated list of values. - Object —
{ }around comma-separated"key": valuepairs. - Null — Literal
null(lowercase).
- Key–value pairs — Inside objects, each key is a JSON string, followed by
:, then the value. Members are separated by,with no trailing comma after the last one. - Arrays — Values in
[ ]are separated by commas; elements may mix types. - Objects — Unordered maps in
{ }; keys must be unique within one object.
Example of JSON syntax
One object describes a person: primitives for simple fields, an array for hobbies, a nested object for address, and null for an unknown boolean state.
{
"name": "John Doe",
"age": 30,
"isStudent": false,
"hobbies": ["reading", "traveling", "photography"],
"address": {
"street": "123 Main St",
"city": "Anytown",
"country": "USA"
},
"isMarried": null
}How to read it
- Object keys
- Each member name is a JSON string in double quotes:
"name","age","isStudent", and"isMarried"label scalar fields on the person object. - Scalar values
- The literals beside those keys use four JSON value kinds:
"John Doe"(string),30(number),false(boolean), andnull(no value / unknown). "hobbies"- Value is an array in
[ ]: three strings in order, separated by commas. "address"- Value is a nested object in
{ }with its own quoted keys ("street","city","country") and string values.
Parsing JSON in JavaScript
Use JSON.parse to turn JSON text into a plain object you can read with dot or bracket notation.
const jsonString = '{"name": "John Doe", "age": 30}';
const data = JSON.parse(jsonString);
console.log(data.name); // "John Doe"
console.log(data.age); // 30For malformed input, JSON.parse throws SyntaxError. The JSON.parse() tutorial covers errors, the reviver callback, and safe handling. To serialize back to text, use JSON.stringify().
Key takeaways
Objects use { } with double-quoted keys; arrays use [ ]; members and elements are comma-separated.
Only six value types exist; everything else must be encoded as one of them (for example dates as strings).
JSON.parse is the standard way to consume JSON text in the browser; pair it with validation for data you did not author.
Frequently asked questions
null as well as objects and arrays. Many APIs still choose { } or [ ] at the root for clarity.Next: JSON Data Types
After syntax, zoom in on strings, numbers, booleans, null, objects, and arrays the way parsers see them.
JSON strings are sequences of Unicode code points in double quotes. Line breaks and control characters must use escapes such as \n and \uXXXX; raw newlines inside a string make the whole document invalid.
10 people found this page helpful
