2 / 2design your own complex, valid JSON Schema
Sure, here's an example of a complex, valid JSON Schema that describes a fictional e-commerce website's product data:
json{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Product",
"description": "Schema for a product on an e-commerce website",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string",
"maxLength": 100
},
"description": {
"type": "string",
"maxLength": 500
},
"price": {
"type": "number",
"minimum": 0
},
"brand": {
"type": "string",
"maxLength": 50
},
"category": {
"type": "string",
"enum": ["electronics", "clothing", "books"]
},
"tags": {
"type": "array",
"items": {
"type": "string",
"maxLength": 20
}
},
"image": {
"type": "string",
"format": "uri"
},
"variants": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string",
"maxLength": 100
},
"price": {
"type": "number",
"minimum": 0
},
"image": {
"type": "string",
"format": "uri"
},
"options": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"maxLength": 50
},
"values": {
"type": "array",
"items": {
"type": "string",
"maxLength": 50
}
}
},
"required": ["name", "values"]
}
}
},
"required": ["id", "name", "price", "options"]
}
}
},
"required": ["id", "name", "description", "price", "brand", "category", "tags", "image", "variants"]
}
This JSON Schema describes a product object that has the following properties:
id
: An integer representing the product ID.name
: A string representing the name of the product, with a maximum length of 100 characters.description
: A string representing the description of the product, with a maximum length of 500 characters.price
: A number representing the price of the product, with a minimum value of 0.brand
: A string representing the brand of the product, with a maximum length of 50 characters.category
: A string representing the category of the product, which can only be one of the following values: "electronics", "clothing", or "books".tags
: An array of strings representing the tags associated with the product, with a maximum length of 20 characters per tag.image
: A string representing the URL of the product image, formatted as a URI.variants
: An array of objects representing the product variants, where each variant has the following properties:id
: An integer representing the variant ID.name
: A string representing the name of the variant, with a maximum
give me three example objects that adhere to that schema
Sure! Here are three example objects that adhere to the schema:
- Example product object with one variant:
json{
"id": 1,
"name": "Smartphone",
"description": "A high-end smartphone with cutting-edge features.",
"price": 999.99,
"brand": "Samsung",
"category": "electronics",
"tags": ["smartphone", "high-end", "Samsung"],
"image": "https://example.com/smartphone.jpg",
"variants": [
{
"id": 1,
"name": "128GB",
"price": 999.99,
"image": "https://example.com/smartphone-128gb.jpg",
"options": [
{
"name": "Color",
"values": ["black", "silver"]
},
{
"name": "Carrier",
"values": ["Verizon", "AT&T", "T-Mobile"]
}
]
}
]
}
- Example product object with multiple variants:
json{
"id": 2,
"name": "T-Shirt",
"description": "A classic cotton t-shirt for everyday wear.",
"price": 19.99,
"brand": "Hanes",
"category": "clothing",
"tags": ["t-shirt", "cotton", "Hanes"],
"image": "https://example.com/t-shirt.jpg",
"variants": [
{
"id": 1,
"name": "Small",
"price": 19.99,
"image": "https://example.com/t-shirt-small.jpg",
"options": [
{
"name": "Color",
"values": ["white", "black", "gray"]
}
]
},
{
"id": 2,
"name": "Medium",
"price": 19.99,
"image": "https://example.com/t-shirt-medium.jpg",
"options": [
{
"name": "Color",
"values": ["white", "black", "gray"]
}
]
},
{
"id": 3,
"name": "Large",
"price": 19.99,
"image": "https://example.com/t-shirt-large.jpg",
"options": [
{
"name": "Color",
"values": ["white", "black", "gray"]
}
]
}
]
}
- Example product object with no variants:
json{
"id": 3,
"name": "The Great Gatsby",
"description": "A classic novel by F. Scott Fitzgerald.",
"price": 12.99,
"brand": "Penguin Books",
"category": "books",
"tags": ["fiction", "classic", "F. Scott Fitzgerald"],
"image": "https://example.com/great-gatsby.jpg",
"variants": []
}
All of these objects adhere to the schema and include all of the required properties, as well as any additional properties that are allowed by the schema.