JSON for Beginners: Syntax, Examples, and First Steps
A practical beginner guide to JSON syntax, nesting, arrays, and safe habits for reading and writing valid documents.
Who this guide is for
If you have never written JSON by hand, this walkthrough is for you. You will learn the rules that matter, see complete examples, and pick up habits that prevent the most common mistakes. You do not need deep JavaScript knowledge—only curiosity about how modern apps move data.
Your first valid document
Create a file named hello.json and paste:
{
"greeting": "Hello, world",
"count": 1
}
That is a complete JSON document: one object with two properties. Save it, then open it in any formatter or validator. If the tool accepts it, you are already writing legal JSON.
Rules you should memorize early
- Use double quotes for keys and string values.
- Separate properties with commas, but never leave a trailing comma after the last item.
- Nest with care — objects inside objects, arrays inside objects, and so on.
- Numbers are bare — write
10, not"10", unless you truly need a string. - Booleans and null are lowercase —
true,false,null.
Invalid example (trailing comma):
{
"ok": true,
}
Valid version:
{
"ok": true
}
Arrays and nesting
Arrays hold ordered values of any JSON type:
{
"skills": ["json", "http", "apis"],
"scores": [9, 8.5, 10],
"flags": [true, false]
}
Nesting lets you model real entities:
{
"orderId": "ORD-1001",
"customer": {
"name": "Sam Rivera",
"email": "sam@example.com"
},
"items": [
{ "sku": "A1", "qty": 2 },
{ "sku": "B3", "qty": 1 }
]
}
Indentation is optional for machines but essential for humans. Pretty-printed JSON with two-space indents is the usual convention in code reviews.
How beginners usually break JSON
- Copying JavaScript objects that use single quotes or unquoted keys
- Adding comments (JSON has no comments in the official standard)
- Mixing tabs and broken quotes after paste from chat apps
- Treating
undefinedas a value (usenullor omit the key)
When something fails, paste the text into a trusted validator. JSON Editor highlights syntax issues and lets you format the document so the structure becomes obvious.
Reading JSON in everyday work
You will meet JSON in browser DevTools Network panels, Postman collections, OpenAPI examples, and error logs. Practice reading from the outside in: identify the root type (object or array), then expand one path at a time. Ask: which keys are required? which values can be null? which lists can be empty?
A simple practice routine
- Write a profile object with name, age, and hobbies array.
- Add an address nested object.
- Minify the file, then pretty-print it again.
- Intentionally break a quote and fix it with a validator.
Fifteen minutes of deliberate practice beats hours of vague reading. Once syntax feels automatic, move on to APIs, schemas, and path queries—still using the same core vocabulary you learned here.
Related articles
Basics · 3 min read
What Is JSON? A Clear Introduction for Developers
Learn what JSON is, why it became the standard for APIs and configs, and how objects, arrays, and data types work in practice.
APIs · 3 min read
JSON API Tutorial: Designing Clean Request and Response Bodies
Practical patterns for JSON APIs including envelopes, errors, pagination, versioning, and examples you can adapt.
Best Practices · 3 min read
JSON Best Practices for Maintainable APIs and Configs
Field-tested JSON best practices covering naming, nulls, versioning, size, security, and documentation habits.