Ankit Lawaniya
 The JSON Schema validator evaluates JSON payloads at runtime
and verifies that they match a referenced JSON schema. We can
match against schemas that exist in a local file or in an external
URI.
 If the payload is not compliant with JSON schema then we will get
the below Exception:
org.mule.module.json.validation.JsonSchemaValidationException: Json
content is not compliant with schema
This feature is specially useful when we are consuming a service that
expects JSON inputs and that must match a specific schema. Only the
JSON payload which is successfully validated against schema will pass
through otherwise JSON schema validation exception will be raised.
Syntax:
<json:validate-schema schemaLocation="EmployeeSchema.json"
doc:name="Validate Json Schema" />
Let’s walk through how to use JSON Schema validator in Mule
application.
Using the JSON Schema Validator is very simple: We only need to
provide a reference to the schema file you want to validate against on
schemaLocation. The Schema Validator accepts both local and external
resources.In this example we have "EmployeeSchema.json" located in
src/main/resources folder . We are expecting the JSON payload as part
of the request which will be validated aganist the schema.
Success Request:
{
"firstName": "Ankit",
"lastName": "Lawaniya",
"age": 28
}
Failed Request:
{
"firstName": "Ankit",
"age": 28
}
Validate json schema component

Validate json schema component

  • 1.
  • 2.
     The JSONSchema validator evaluates JSON payloads at runtime and verifies that they match a referenced JSON schema. We can match against schemas that exist in a local file or in an external URI.  If the payload is not compliant with JSON schema then we will get the below Exception: org.mule.module.json.validation.JsonSchemaValidationException: Json content is not compliant with schema
  • 3.
    This feature isspecially useful when we are consuming a service that expects JSON inputs and that must match a specific schema. Only the JSON payload which is successfully validated against schema will pass through otherwise JSON schema validation exception will be raised. Syntax: <json:validate-schema schemaLocation="EmployeeSchema.json" doc:name="Validate Json Schema" />
  • 4.
    Let’s walk throughhow to use JSON Schema validator in Mule application. Using the JSON Schema Validator is very simple: We only need to provide a reference to the schema file you want to validate against on schemaLocation. The Schema Validator accepts both local and external resources.In this example we have "EmployeeSchema.json" located in src/main/resources folder . We are expecting the JSON payload as part of the request which will be validated aganist the schema.
  • 7.
  • 8.