π’ JSON Data Types β A Complete Guide with Examples
π Overview β Understand the Core JSON Value Types
JSON supports a concise set of core data types that power structured data exchange. Whether you’re defining configuration files or consuming API payloads, mastering these types ensures your data is valid, understandable, and interoperable.
π What Youβll Learn:
- The 7 fundamental JSON data types
- Syntax examples for each type
- How types combine within objects and arrays
- How whitespace is treated in JSON
π Topics Covered
π’ Topic | π Description |
---|---|
π JSON Number | Integers or decimal numbers (42 , 3.14 ) |
π JSON String | Text enclosed in double quotes ("hello" ) |
π’ JSON Boolean | Logical values: true or false |
π JSON Array | Ordered list: [value1, value2, ...] |
π JSON Object | Unordered key-value pairs: { "key": value } |
β JSON null | Represents no value (null ) |
βοΈ JSON Whitespace Handling | Whitespace (spaces, tabs, line breaks) are ignored |
π JSON Number
- Represent integers or decimals.
- No quotes required.
{ "count": 100, "ratio": 3.14 }
π JSON String
- Must be wrapped in double quotes (
"
). - Supports escaped characters:
\n
,\"
,\\
.
{ "message": "Hello, \"world\"!\nWelcome." }
π’ JSON Boolean
- True or false logic values.
{ "isActive": true, "isAdmin": false }
π JSON Array
- A list of JSON values (any types).
- Values separated by commas.
{ "tags": ["angular", "json", 2025, true] }
π JSON Object
- Key-value pairs; keys must be strings in quotes.
- Values can be any JSON type.
{
"id": 1,
"user": {
"name": "Bob",
"roles": ["reader", "author"]
}
}
β JSON null
- Denotes absence of a valueβnot the same as undefined.
{ "comment": null }
βοΈ JSON Whitespace Handling
- JSON ignores spaces, tabs, newlines outside string literals.
- Format freely for readability.
{
"a": 1,
"b": [2, 3],
"c": {
"d": null
}
}
Equivalent to a compact, single-line JSON.
π Summary β Key Takeaways
Understanding JSON data types is foundational to consistent data modeling:
- Numbers, strings, booleans, arrays, objects, and null cover typical needs.
- Whitespace is flexibleβused for clarity without impacting content.
- Nesting arrays and objects unlocks complex, structured payloads.
These types underpin virtually all JSON usage in REST APIs, configs, and client-side storage.
β Frequently Asked Questions (FAQs)
β Can JSON arrays mix types?
β
Yesβarrays may contain mixed types: numbers, strings, objects, booleans, and null
.
β Are keys required to be quoted?
β Yes, object keys must always be in double quotes.
β Is undefined
valid in JSON?
β Noβuse null
for empty or missing values.
β Does JSON preserve formatting?
β Data remains the same, formatting (line breaks/spaces) is ignored outside strings.
β How do I parse JSON safely?
β
Use built-in parsers (JSON.parse()
in JavaScript) or validators to avoid injection errors.
Share Now :