Validate JSON
This policy can be used to validate whether a request or response conforms to the schema specified. The policy takes the JSON schema based on the specification defined in the article provided in the following link: http://json-schema.org/latest/json-schema-core.html.The validation will be successful if the payload conforms to the JSON schema specified in the policy configuration.
Figure 1: Validate JSON policy with a sample schema
Example:
Given below is a basic JSON schema to be specified in the policy configuration.
Basic JSON schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
}
},
"required": ["id", "name", "price"]
}
Given below is a sample payload which conforms to the JSON schema specified.
Payload
{ "id": 2, "name": "An ice sculpture", "price": 12.50}