Defining JSON Schema¶
You can refer to the following JSON schema format to define your schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"<property_name_1>": {
"type": "<data_type>",
"description": "<description_of_the_property>"
},
"<property_name_2>": {
"type": "<data_type>",
"format": "<optional_format>",
"enum": ["<value1>", "<value2>", "<value3>"],
"description": "<description_of_the_property>"
}
},
"required": ["<required_property_1>", "<required_property_2>"]
}
Here is a step-by-step guide to help you define your JSON schema:
- Create the schema object:
- Set
type: "object"
to specify the root level as an object type. - Add a
properties
object to define all fields.
- Set
- Define property names:
- Create an object for each property, including
type
anddescription
. - Common types:
string
,number
,boolean
,array
,object
. - For arrays, use
items
to define element types.
- Create an object for each property, including
- Set constraints:
- Add a
required
array at each level, listing all required fields.
- Add a
- Handle special fields:
- Use
enum
to restrict optional values.
- Use