JSON Data Types
15 April 2025 | Category: JavaScript
In JSON (JavaScript Object Notation), data is represented using a small set of well-defined data types. These types are used to hold different kinds of values like text, numbers, lists, or even other structured data.
JSON supports six basic data types, all of which are easy to understand and use.
✅ List of JSON Data Types
Data Type | Description | Example |
---|---|---|
String | A sequence of characters | "name": "Alice" |
Number | Numeric values (integer or float) | "age": 25 |
Boolean | Logical value: true or false | "isStudent": false |
Array | A list of values in order | "skills": ["HTML", "CSS"] |
Object | A collection of key/value pairs | "address": { "city": "Delhi" } |
Null | Represents an empty or unknown value | "spouse": null |
🔎 JSON Data Type Examples
1. String
A string must be wrapped in double quotes.
{
"firstName": "John"
}
2. Number
No quotes are used. Can be integer or floating-point.
{
"age": 30,
"height": 5.9
}
3. Boolean
Must be lowercase: true
or false
.
{
"isActive": true
}
4. Array
A list of values enclosed in square brackets []
. It can contain multiple data types.
{
"colors": ["red", "green", "blue"],
"marks": [85, 90, 78]
}
5. Object
Enclosed in curly braces {}
, with key/value pairs inside.
{
"person": {
"name": "Rahul",
"age": 22
}
}
6. Null
Used to represent “no value”.
{
"middleName": null
}
🧠 Important Notes
- Keys must always be strings.
- You can nest arrays and objects to create complex data structures.
- JSON does not support functions, dates (as native types), or comments.
🎯 Summary
- JSON supports 6 main data types: String, Number, Boolean, Array, Object, and Null.
- Each type has a specific structure and usage.
- JSON is ideal for representing structured data for APIs and web communication.