MuleSoft best practices for JSON Schema Validation provide a reliable method to validate JSON data structure using the JSON Schema specification. It validates input data at runtime and verifies whether they match a referenced schema or not. We can match against defined schemas that exist in a local file or an external URI.

If the payload is incorrect with the given JSON schema, then the compiler throws the below exception:

org.mule.module.json.validation.JsonSchemaValidationException: JSON content is not compliant with schema.

Use Case

Validating the input JSON payload against the JSON Schema.

JSON Payload:

  "firstName": "Murali",
  "lastName": "Krishna",
  "age" : 26

JSON Schema:

  "$schema": "",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    "lastName": {
      "type": "string"
    "age": {
      "type": "integer"
  "required": [

Mule Flow

Step 1:

Configure the HTTP Listener by giving the hostname, port number, and path along with the specified allowed methods (Optional) on an Advanced tab of the HTTP connector.

Step 2:

Drag and Drop the JSON Validate Schema from Mule Palette to validate the input payload. And provide the schema path. In my case it is like the following:


From the above line,

schemas —-> It is a directory

Sample-Schema.json —-> It is a JSON-Schema structure for validation.

Syntax of JSON Validator as below:

<json:validate-schema doc:name="Validate schema" doc:id="5a8b10e1-59e8-4f68-9aaa-303c9cb5c9d6" schema="schemas/Sample-Schema.json">

Step 3:

Drag and drop the Logger component to log the resultant payload after the validation.

Final Config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="" xmlns:validation=""
xmlns:http="" xmlns="" xmlns:doc="" xmlns:xsi="" xsi:schemaLocation="">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="8a601d72-5913-4ed7-99d3-707601301ec9" >
<http:listener-connection host="" port="8080" />
<flow name="abcFlow" doc:id="30917fd1-0429-4ec7-9d7d-aa8d4d19413e" >
<http:listener doc:name="Listener" doc:id="2b89fed0-69ce-47eb-93bf-3bd0628fe188" config-ref="HTTP_Listener_config" path="abc" allowedMethods="POST">
<ee:repeatable-file-store-stream />
<json:validate-schema doc:name="Validate schema" doc:id="5a8b10e1-59e8-4f68-9aaa-303c9cb5c9d6" schema="schemas/Sample-Schema.json">
<logger level="INFO" doc:name="Logger" doc:id="26b62866-2f25-4374-9d95-9fe14c052366" message="Payload is Validated ----> #[message.payload]" />

Success Scenario:

mule 4 json schema validation

Failure Scenario:

mule 4 json schema validation

XTIVIA Blog CTA MuleSoft

This post was originally published here.

Are you still having trouble with Mule 4 and MuleSoft integration? Let our MuleSoft experts help get you past any issues you may be experiencing, or even complete the task for you. Contact us to speak with one of our MuleSoft experts now!

Share This