JSON Example With Data Types and Arrays (Beginner Guide)
Our guides are based on hands-on testing and verified sources. Each article is reviewed for accuracy and updated regularly to ensure current, reliable information.Read our editorial policy.
Ever stared at a JSON blob and wondered what every curly brace and square bracket meant? You’re not alone.
Spoiler: JSON is simpler than you think. Let me walk you through it quickly.
Why JSON matters?
JSON (JavaScript Object Notation) is everywhere. APIs speak it. Config files use it. Marketers—hi—send data with it.
JSON is a lightweight, text‑based format for data interchange. That lightweight part matters. It’s why your websites load quickly and your analytics tools talk to each other.
Knowing the six data types makes the rest easy: four primitives, string, number, boolean, and null, and two compound types, object and array.
Here’s the thing: there’s no “date” type. Dates are just strings. JSON is intentionally simple. That said, mixing types can trip you up if you don’t know the rules.
Suggested Read: JSON vs. XML for APIs: Key Differences Explained for Beginners
Valid JSON Data Types
Let’s break them down.
#1 Strings: double quotes only
Strings hold text. They must be in double quotes. Single quotes won’t work. Strings can be empty.
Use strings for names, descriptions, and emails. Here’s a quick example:
{"name": "Sahil", "city": "Delhi"}Keep strings quoted, and don’t wrap numbers or booleans in quotes.
#2 Numbers: only base 10
Numbers represent integers or floating‑point values. There are no octal or hexadecimal numbers. If you need 0xFF, convert it first. JSON also treats 17, 4.2, and 2.99792e8 as the same type, there’s no separate integer type.
Example:
{"age": 28, "price": 19.99, "rating": 4.8, "discount": 0.15}Numbers can be negative. Just add a minus sign, no quotes. Use numbers for ages, prices, coordinates and scores. Remember: trailing commas after numbers are not allowed.
#3 Booleans: true or false
Booleans are simple: true or false. Lowercase only. No quotes. No 1 or 0. These values control feature flags, statuses and toggles. For example:
{"isActive": true, "isVerified": false, "hasAccess": true}Use booleans for feature flags, statuses and toggles. Don’t store “yes” or “no” as strings.
#4 Null: absence made explicit
Null represents an intentionally empty field. It’s its own data type. It’s not the same as an empty string or zero. Use it when data is unknown or intentionally omitted:
{"middleName": null, "profileImage": null, "endDate": null}This tells downstream consumers that the field exists but currently has no value. Null helps APIs avoid guesswork. When you convert your JSON to typed languages, null usually maps to None or nil.
#5 Objects: key–value maps
Objects group related data. They’re enclosed in curly braces {} and contain key–value pairs separated by commas. Keys must be strings (in double quotes), values can be any JSON type.
Example:
{
"user": {
"name": "Peter",
"age": 20,
"score": 50.05
},
"settings": {
"theme": "dark",
"notifications": true
}
}Objects are unordered. Ordering keys has no semantic meaning. That can frustrate you, like when a back-end returns keys in a different order than you expect. That said, treat objects like dictionaries; if order matters, you probably needed an array.
#6 Arrays: ordered lists that hold anything
Arrays are where JSON gets flexible. An array is an ordered list of values enclosed in square brackets. Order matters.
The first element has index 0. Elements are separated by commas, and arrays can contain strings, numbers, booleans, objects, other arrays or nulls.
Example of a simple array:
{"skills": ["JavaScript", "Python", "SQL"]}Arrays can mix types:
{"mixed": ["text", 123, true, null, {"key": "value"}, [1, 2, 3]]}Arrays preserve order, important for lists of events or ordered steps. But watch out: trailing commas are illegal.
Many JSON linters catch this, but some editors don’t. That said, you can nest arrays deeply. Just keep your structure readable. Use arrays for lists of items, messages, or any collection where order matters.
Best practices for arrays
- Keep types consistent. Although arrays can mix types, sticking to a single type makes processing easier.
- Never end with a comma. JSON doesn’t allow a trailing comma after the last element.
- Arrays are powerful and make lists trivial. Misusing them, like storing unnamed fields that belong in an object, will bite you later.
#7 Bringing it together: a complete JSON example
You’ve seen each type alone. Now let’s combine them.
Here’s a JSON document that uses every data type. I built this because I wanted a single example I could reference.
{
"event": {
"id": 987,
"title": "Webinar on APIs",
"date": "2026-03-15",
"durationHours": 2.5,
"isLive": false,
"host": null,
"speaker": {
"name": "Alex",
"age": 34,
"experienceYears": 10,
"expert": true,
"topics": [
"JSON",
"APIs",
"Security"
]
},
"attendees": [
{
"name": "Sam",
"age": 28,
"registered": true,
"sessions": [
1,
3
]
},
{
"name": "Lea",
"age": 31,
"registered": false,
"sessions": []
}
]
}
}Here’s what’s happening:
- Strings: “title”, “date”, “name”, “topics” fields hold text.
- Numbers: 987, 2.5, 34, 28—integers and floats mixed.
- Booleans: isLive and registered flags show statuses.
- Null: host has no value assigned yet.
- Objects: event, speaker, and each attendee.
- Arrays: topics holds strings; attendees is an array of objects; each attendee has a sessions array of numbers.
This structure is easy to parse. You can loop through attendees by index and access sessions. Always document your schema: JSON doesn’t enforce types or required fields.
When arrays bite back?
Mixing types in an array is legal, but it can confuse consumers. Use it only when each position has a clear meaning. Trailing commas are also invalid, so validate your JSON with tools like CodeItBro.
Arrays vs. objects: picking the right structure
Use objects when you need named keys; use arrays when order matters. Objects are unordered, while arrays preserve order.
You’re now equipped to build JSON. Start small: an object with a few strings. Add numbers, booleans, and nulls. Wrap some items in an array. Validate with an online tool.
JSON’s simplicity is its strength and its trap. It doesn’t enforce schemas; it accepts mixed types. Document your structure. Avoid trailing commas. Keep arrays consistent when possible. Use null intentionally. Keep strings quoted. Follow these rules, and JSON will work for you.
Now you know how each data type works and how arrays hold everything together. Go build clean, valid JSON.


