Sure! Here's a simple example of using JSON Schema to validate a user profile object:
JSON Schema Example
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"username": {
"type": "string",
"minLength": 3
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0
}
},
"required": ["username", "email"]
}
Explanation
$schema: Specifies the version of JSON Schema being used.type: Indicates that the data should be an object.properties: Defines the expected fields:username: Must be a string with a minimum length of 3 characters.email: Must be a valid email format.age: Must be a non-negative integer.
required: Specifies thatusernameandemailmust be present.
Usage
You can use this schema to validate JSON data representing a user profile. If the data meets the schema's requirements, it is considered valid.
If you have more questions or need further examples, feel free to ask!
