BASICS
JSON Basics: Syntax, Types, Objects, and Arrays
JSON is a compact text format for representing structured data. This guide walks through its building blocks so you can read, write, and check a JSON document with confidence.
What is JSON?
JSON stands for JavaScript Object Notation. Despite its name, it is a language-independent data format, not JavaScript code. Programs use JSON text to exchange information, store configuration, and describe structured records. Web APIs commonly return JSON in HTTP responses, and many tools can read or write it.
A JSON document contains a value. That value can be an object, an array, a string, a number, a boolean, or null. Objects and arrays can contain other JSON values, which is how larger structures are built.
Objects: named properties
An object is enclosed in curly braces. It contains zero or more key-value pairs. Each key is a double-quoted string, followed by a colon, followed by a value. Commas separate pairs.
{
"name": "Ari Chen",
"active": true,
"role": "developer"
}Here, name, active, and role are keys. Their associated values are a string, a boolean, and another string. Keys in the same object should be unique so readers and programs do not have to guess which duplicate value to use.
Arrays: ordered values
An array is enclosed in square brackets. It stores values in order, and the values do not need property names. Commas separate array items.
[
"format",
"validate",
"convert"
]Arrays can also contain objects, numbers, booleans, or a mixture of JSON value types. For a list of similar records, an array of objects is common.
The six JSON value types
- String: text surrounded by double quotes, such as
"hello". Escape a quote inside a string as\". - Number: an integer or decimal number, optionally with an exponent, such as
12,-0.5, or2e3. JSON has no separate integer type. - Boolean: exactly
trueorfalse, in lowercase. - Null: the literal
null, used to represent an explicitly absent or unknown value. - Object: a collection of named properties inside
{}. - Array: an ordered collection of values inside
[].
JSON does not have undefined, comments, functions, dates, or NaN as native values. Dates are usually represented as strings in a documented format, often an ISO-style timestamp.
Nesting objects and arrays
Objects and arrays can appear inside one another. Indentation is optional to the JSON parser, but it helps people see which values belong together.
{
"user": {
"id": 42,
"name": "Ari Chen",
"active": true,
"profile": {
"city": "Portland",
"bio": null
},
"skills": ["HTML", "CSS", "JavaScript"]
}
}To read a nested value, follow its keys and array positions from the root. In this example, the city is at user.profile.city, and the first skill is at user.skills[0].
Rules for valid JSON
- Property names and strings use double quotes.
- Every property has a colon between its key and value.
- Commas separate items, but there is no comma after the last item.
- Braces and brackets must be paired and correctly nested.
- Use lowercase
true,false, andnull. - Do not include comments or extra text before or after the JSON value.
For a syntax check, paste a document into the JSON Validator. To make valid JSON easier to read, use the JSON Formatter.
Key takeaways
- JSON is text representing one structured value.
- Objects group named properties; arrays hold ordered items.
- Strings, numbers, booleans, and null are the primitive JSON types.
- Strict punctuation and quoting rules matter; formatting does not change the underlying data.