Your First JSON Object
A JSON object is a collection of key-value pairs wrapped in curly braces {}. Think of it like a dictionary or a filled-in form — each field has a name (the key) and a value. Keys are always strings in double quotes. Values can be any of the six JSON data types.
{
"name": "Alice",
"age": 30,
"email": "[email protected]",
"active": true
}Anatomy of a JSON object
Every JSON object follows the same structure:
- Key — a string in double quotes, e.g.
"name" - Colon — separates key from value:
: - Value — any valid JSON value
- Comma — separates pairs from each other (no comma after the last pair)
{
"key": "value",
"anotherKey": 42
}What types of values are allowed?
A value in a JSON object can be:
- A string:
"hello" - A number:
42or3.14 - A boolean:
trueorfalse - Null:
null - Another object:
{"city": "Paris"} - An array:
[1, 2, 3]
Here is an object that uses all six types at once:
{
"username": "alice123",
"score": 9850,
"verified": true,
"nickname": null,
"profile": {
"city": "London"
},
"badges": ["gold", "silver"]
}How do I write my first JSON object?
Start small. Pick a thing you want to describe — a person, a product, a config setting — and list its properties:
- Open with
{ - Write each property as
"key": value - Separate properties with commas
- Do not put a comma after the last property
- Close with
}
{
"product": "Widget",
"price": 9.99,
"inStock": true,
"tags": ["sale", "new"]
}Common beginner mistakes
- Using single quotes:
{'name': 'Alice'}is invalid — always use double quotes - Adding a trailing comma:
{"a": 1,}will cause a parse error - Forgetting quotes around keys:
{name: "Alice"}is JavaScript syntax, not JSON
See JSON Syntax Rules for the full list of rules.
Try it in JSON Prism
Paste your JSON object into the JSON Formatter to check indentation and structure at a glance. Once you have built something more complex, explore The Six JSON Data Types to understand exactly what values you can use.
{"name": "Your Name", "favoriteColor": "blue", "luckyNumber": 7}