Getting Started

JSON Schema examples

In this page, you will find examples illustrating different use cases to help you get the most out of your JSON Schemas. These examples cover a wide range of scenarios, and each example comes with accompanying JSON data and explanation, showcasing how JSON Schemas can be applied to various domains. You can modify these examples to suit your specific needs, as this is just one of the many ways you can utilize JSON Schemas.

Address

A schema representing an address, with optional properties for different address components which enforces that locality, region, and countryName are required, and if postOfficeBox or extendedAddress is provided, streetAddress must also be provided.

schema
1
{
2
"$id": "https://example.com/address.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "An address similar to http://microformats.org/wiki/h-card",
5
"type": "object",
6
"properties": {
7
"postOfficeBox": {
8
"type": "string"
9
},
10
"extendedAddress": {
11
"type": "string"
12
},
13
"streetAddress": {
14
"type": "string"
15
},
16
"locality": {
17
"type": "string"
18
},
19
"region": {
20
"type": "string"
21
},
22
"postalCode": {
23
"type": "string"
24
},
25
"countryName": {
26
"type": "string"
27
}
28
},
29
"required": [ "locality", "region", "countryName" ],
30
"dependentRequired": {
31
"postOfficeBox": [ "streetAddress" ],
32
"extendedAddress": [ "streetAddress" ]
33
}
34
}

Data

data
1
{
2
"postOfficeBox": "123",
3
"streetAddress": "456 Main St",
4
"locality": "Cityville",
5
"region": "State",
6
"postalCode": "12345",
7
"countryName": "Country"
8
}

Blog post

A schema representing a blog post, including properties like title, content, publishedDate, author, and tags.

schema
1
{
2
"$id": "https://example.com/blog-post.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "A representation of a blog post",
5
"type": "object",
6
"required": ["title", "content", "author"],
7
"properties": {
8
"title": {
9
"type": "string"
10
},
11
"content": {
12
"type": "string"
13
},
14
"publishedDate": {
15
"type": "string",
16
"format": "date-time"
17
},
18
"author": {
19
"$ref": "https://example.com/user-profile.schema.json"
20
},
21
"tags": {
22
"type": "array",
23
"items": {
24
"type": "string"
25
}
26
}
27
}
28
}

Data

data
1
{
2
"title": "New Blog Post",
3
"content": "This is the content of the blog post...",
4
"publishedDate": "2023-08-25T15:00:00Z",
5
"author": {
6
"username": "authoruser",
7
"email": "author@example.com"
8
},
9
"tags": ["Technology", "Programming"]
10
}

Calendar

A schema representing an event in a calendar, including properties like startDate, endDate, summary, location, and recurrenceDate details. The geo property is a reference ($ref) to another schema defined at a different location which represents a geographical location with latitude and longitude values.

schema
1
{
2
"$id": "https://example.com/calendar.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "A representation of an event",
5
"type": "object",
6
"required": [ "dtstart", "summary" ],
7
"properties": {
8
"startDate": {
9
"type": "string",
10
"description": "Event starting time"
11
},
12
"endDate": {
13
"type": "string",
14
"description": "Event ending time"
15
},
16
"summary": {
17
"type": "string"
18
},
19
"location": {
20
"type": "string"
21
},
22
"url": {
23
"type": "string"
24
},
25
"duration": {
26
"type": "string",
27
"description": "Event duration"
28
},
29
"recurrenceDate": {
30
"type": "string",
31
"description": "Recurrence date"
32
},
33
"recurrenceDule": {
34
"type": "string",
35
"description": "Recurrence rule"
36
},
37
"category": {
38
"type": "string"
39
},
40
"description": {
41
"type": "string"
42
},
43
"geo": {
44
"$ref": "https://example.com/geographical-location.schema.json"
45
}
46
}
47
}

Data

data
1
{
2
"startDate": "2023-08-25T10:00:00Z",
3
"endDate": "2023-08-25T12:00:00Z",
4
"summary": "Conference Presentation",
5
"location": "Conference Center",
6
"recurrenceDule": "FREQ=DAILY;COUNT=5"
7
}

Device type

This schema represents electronic devices with a deviceType property that determines the device's category, such as smartphone or laptop. It employs the oneOf keyword to dynamically reference schemas based on the deviceType property. This flexible schema structure allows data to conform to the appropriate device schema based on the deviceType specified, making it easy to describe different electronic devices with their unique characteristics. When deviceType is set to smartphone, the schema enforces properties specific to smartphones, and when deviceType is set to laptop, it enforces properties specific to laptops.

data
1
{
2
"$id": "https://example.com/device.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"type": "object",
5
"properties": {
6
"deviceType": {
7
"type": "string"
8
}
9
},
10
"required": ["deviceType"],
11
"oneOf": [
12
{
13
"properties": {
14
"deviceType": { "const": "smartphone" }
15
},
16
"$ref": "https://example.com/smartphone.schema.json"
17
},
18
{
19
"properties": {
20
"deviceType": { "const": "laptop" }
21
},
22
"$ref": "https://example.com/laptop.schema.json"
23
}
24
]
25
}
26

27
{
28
"$id": "https://example.com/smartphone.schema.json",
29
"$schema": "https://json-schema.org/draft/2020-12/schema",
30
"type": "object",
31
"properties": {
32
"brand": {
33
"type": "string"
34
},
35
"model": {
36
"type": "string"
37
},
38
"screenSize": {
39
"type": "number"
40
}
41
},
42
"required": ["brand", "model", "screenSize"]
43
}
44

45
{
46
"$id": "https://example.com/laptop.schema.json",
47
"$schema": "https://json-schema.org/draft/2020-12/schema",
48
"type": "object",
49
"properties": {
50
"brand": {
51
"type": "string"
52
},
53
"model": {
54
"type": "string"
55
},
56
"processor": {
57
"type": "string"
58
},
59
"ramSize": {
60
"type": "number"
61
}
62
},
63
"required": ["brand", "model", "processor", "ramSize"]
64
}

Data

data
1
{
2
"deviceType": "smartphone",
3
"brand": "Samsung",
4
"model": "Galaxy S21",
5
"screenSize": 6.2
6
}

Ecommerce system

A schema representing an ecommerce system, where $anchor is used within the definitions of product and order schemas to define anchor points: ProductSchema and OrderSchema, respectively.

schema
1
{
2
"$id": "https://example.com/ecommerce.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"$defs": {
5
"product": {
6
"$anchor": "ProductSchema",
7
"type": "object",
8
"properties": {
9
"name": { "type": "string" },
10
"price": { "type": "number", "minimum": 0 }
11
}
12
},
13
"order": {
14
"$anchor": "OrderSchema",
15
"type": "object",
16
"properties": {
17
"orderId": { "type": "string" },
18
"items": {
19
"type": "array",
20
"items": { "$ref": "#ProductSchema" }
21
}
22
}
23
}
24
}
25
}

Data

data
1
{
2
"order": {
3
"orderId": "ORD123",
4
"items": [
5
{
6
"name": "Product A",
7
"price": 50
8
},
9
{
10
"name": "Product B",
11
"price": 30
12
}
13
]
14
}
15
}

Geographical location

A schema representing geographical coordinates with latitude and longitude values within specified ranges.

schema
1
{
2
"$id": "https://example.com/geographical-location.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"title": "Longitude and Latitude Values",
5
"description": "A geographical coordinate.",
6
"required": [ "latitude", "longitude" ],
7
"type": "object",
8
"properties": {
9
"latitude": {
10
"type": "number",
11
"minimum": -90,
12
"maximum": 90
13
},
14
"longitude": {
15
"type": "number",
16
"minimum": -180,
17
"maximum": 180
18
}
19
}
20
}

Data

data
1
{
2
"latitude": 48.858093,
3
"longitude": 2.294694
4
}

Health record

A schema representing a health record, including patientName, dateOfBirth, bloodType, allergies, conditions, medications, and emergencyContact.

schema
1
{
2
"$id": "https://example.com/health-record.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "Schema for representing a health record",
5
"type": "object",
6
"required": ["patientName", "dateOfBirth", "bloodType"],
7
"properties": {
8
"patientName": {
9
"type": "string"
10
},
11
"dateOfBirth": {
12
"type": "string",
13
"format": "date"
14
},
15
"bloodType": {
16
"type": "string"
17
},
18
"allergies": {
19
"type": "array",
20
"items": {
21
"type": "string"
22
}
23
},
24
"conditions": {
25
"type": "array",
26
"items": {
27
"type": "string"
28
}
29
},
30
"medications": {
31
"type": "array",
32
"items": {
33
"type": "string"
34
}
35
},
36
"emergencyContact": {
37
"$ref": "https://example.com/user-profile.schema.json"
38
}
39
}
40
}

Data

data
1
{
2
"patientName": "Jane Doe",
3
"dateOfBirth": "1985-02-15",
4
"bloodType": "A+",
5
"allergies": ["Pollen", "Penicillin"],
6
"conditions": ["Hypertension", "Diabetes"],
7
"medications": ["Lisinopril", "Metformin"],
8
"emergencyContact": {
9
"username": "emergencyuser",
10
"email": "emergency@example.com"
11
}
12
}

Job posting

A schema representing a job posting, including properties like title, company, location, description, employmentType, salary, and applicationDeadline. It also uses the $anchor keyword for defining an anchor.

schema
1
{
2
"$id": "https://example.com/job-posting.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "A representation of a job posting",
5
"type": "object",
6
"required": ["title", "company", "location", "description"],
7
"properties": {
8
"title": {
9
"type": "string"
10
},
11
"company": {
12
"type": "string"
13
},
14
"location": {
15
"type": "string"
16
},
17
"description": {
18
"type": "string"
19
},
20
"employmentType": {
21
"type": "string"
22
},
23
"salary": {
24
"type": "number",
25
"minimum": 0
26
},
27
"applicationDeadline": {
28
"type": "string",
29
"format": "date"
30
}
31
}
32
}

Data

data
1
{
2
"title": "Software Engineer",
3
"company": "Tech Solutions Inc.",
4
"location": "Cityville",
5
"description": "Join our team as a software engineer...",
6
"employmentType": "Full-time",
7
"salary": 80000,
8
"applicationDeadline": "2023-09-15"
9
}

Movie

A schema representing a movie, including properties such as title, director, release date, genre, duration, and cast members.

schema
1
{
2
"$id": "https://example.com/movie.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "A representation of a movie",
5
"type": "object",
6
"required": ["title", "director", "releaseDate"],
7
"properties": {
8
"title": {
9
"type": "string"
10
},
11
"director": {
12
"type": "string"
13
},
14
"releaseDate": {
15
"type": "string",
16
"format": "date"
17
},
18
"genre": {
19
"type": "string",
20
"enum": ["Action", "Comedy", "Drama", "Science Fiction"]
21
},
22
"duration": {
23
"type": "string"
24
},
25
"cast": {
26
"type": "array",
27
"items": {
28
"type": "string"
29
},
30
"additionalItems": false
31
}
32
}
33
}

Data

data
1
{
2
"title": "Sample Movie",
3
"director": "John Director",
4
"releaseDate": "2023-07-01",
5
"genre": "Action",
6
"duration": "2h 15m",
7
"cast": ["Actor A", "Actress B", "Actor C"]
8
}

User profile

A schema representing a user profile, including properties like username, email, fullName, age, location, and interests.

schema
1
{
2
"$id": "https://example.com/user-profile.schema.json",
3
"$schema": "https://json-schema.org/draft/2020-12/schema",
4
"description": "A representation of a user profile",
5
"type": "object",
6
"required": ["username", "email"],
7
"properties": {
8
"username": {
9
"type": "string"
10
},
11
"email": {
12
"type": "string",
13
"format": "email"
14
},
15
"fullName": {
16
"type": "string"
17
},
18
"age": {
19
"type": "integer",
20
"minimum": 0
21
},
22
"location": {
23
"type": "string"
24
},
25
"interests": {
26
"type": "array",
27
"items": {
28
"type": "string"
29
}
30
}
31
}
32
}

Data

data
1
{
2
"username": "user123",
3
"email": "user@example.com",
4
"fullName": "John Doe",
5
"age": 30,
6
"location": "Cityville",
7
"interests": ["Travel", "Technology"]
8
}

Need help?

Learning JSON Schema is often confusing, but don't worry, we are here to help! You can start a thread on GitHub Discussions, connect with us on Slack, or join our live Office Hours.
We'd love to help!! ❤️