DEV Community

Cover image for JSON Example with All Data Types
Pineapple
Pineapple

Posted on

JSON Example with All Data Types

JSON (JavaScript Object Notation) supports multiple data types that allow you to represent complex data structures efficiently. Understanding all JSON data types is essential for API development, data exchange, and configuration management.

What are JSON Data Types?

JSON supports six primary data types:

  1. String - Text data enclosed in double quotes
  2. Number - Numeric values (integers and decimals)
  3. Boolean - True or false values
  4. Null - Represents empty or no value
  5. Object - Collection of key-value pairs
  6. Array- Ordered list of values

Complete JSON Example with All Data Types
Here's a comprehensive example demonstrating all JSON data types in a single document:
{
"user": {
"id": 12345,
"username": "johndoe",
"email": "john@example.com",
"age": 28,
"height": 5.9,
"isActive": true,
"isVerified": false,
"profileImage": null,
"bio": "Full-stack developer",
"skills": ["JavaScript", "Python", "React"],
"address": {
"city": "New York",
"zipCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"socialMedia": {
"twitter": "@johndoe",
"linkedin": "linkedin.com/in/johndoe",
"instagram": null
}
}
}

Detailed Breakdown of JSON Data Types

1. String Data Type
Strings represent text data and must be enclosed in double quotes.

Example:
{
"name": "John Doe",
"email": "john@example.com",
"city": "New York",
"bio": "Software developer passionate about technology"
}

Rules:

  • Must use double quotes (not single quotes)
  • Can contain Unicode characters
  • Can be empty: ""

Use Cases: Names, emails, URLs, descriptions, dates

2. Number Data Type
Numbers can be integers or floating-point values without quotes.
Example:
{
"age": 28,
"price": 19.99,
"quantity": 100,
"temperature": -5.5,
"rating": 4.8,
"discount": 0.15
}

Rules:

  • No quotes around numbers
  • Can be positive or negative
  • Supports decimals and scientific notation

Use Cases: Ages, prices, quantities, coordinates, ratings

3. Boolean Data Type
Booleans represent true or false values (lowercase, no quotes).
Example:
{
"isActive": true,
"isVerified": false,
"hasAccess": true,
"darkMode": false
}

Rules:

  • Only true or false (lowercase)
  • No quotes
  • Cannot be True, False, 1, or 0

Use Cases: Feature flags, permissions, status indicators, settings

4. Null Data Type
Null represents the absence of a value or an explicitly empty field.
Example:
json{
"middleName": null,
"profileImage": null,
"endDate": null,
"spouse": null
}

Rules:

  • Must be lowercase: null
  • Represents intentional absence
  • Different from "", 0, or false

Use Cases: Optional fields, unknown data, cleared values

5. Object Data Type
Objects are collections of key-value pairs enclosed in curly braces {}.
Example:
{
"user": {
"name": "John",
"age": 28
},
"address": {
"city": "New York",
"zipCode": "10001"
},
"settings": {
"theme": "dark",
"notifications": true
}
}

Rules:

  • Enclosed in {}
  • Keys must be strings in double quotes
  • Values separated by colons
  • Can contain nested objects

Use Cases: User profiles, settings, grouped data, nested structures

6. Array Data Type
Arrays are ordered lists of values enclosed in square brackets [].
Example:
{
"skills": ["JavaScript", "Python", "SQL"],
"scores": [95, 87, 92, 88],
"features": [true, false, true],
"mixed": ["text", 123, true, null],
"users": [
{"name": "John", "age": 28},
{"name": "Jane", "age": 25}
]
}

Rules:

  • Enclosed in []
  • Elements separated by commas
  • Can contain any data type
  • Can mix different types

Use Cases: Lists, collections, multiple values, ordered data

JSON's six data types—String, Number, Boolean, Null, Object, and Array—provide the flexibility to represent any data structure. Understanding how to use each type correctly is essential for building APIs, configuration files, and data exchange systems.

Use JSONFormatter.gg to validate, format, and test your JSON with all data types instantly.
Master JSON data types today and build better applications!

Top comments (0)