Author: Pankaj Badi
- First we need the JSON data for creating the body in POST Method.
- To check that data is valid or not?
- You can check that on this link https://jsonlint.com/.
- This link can show you the data is valid or not.

- You will get the result.

- Take the listener in anypoint studio and give the properties and configuration according to your convenience.

- Now convert the JSON validate data into JSON Schema.

- For that you will get link
- https://www.liquid-technologies.com/online-json-to-schema-converter
- You will get the data in this form.

- In src/main/resources you will find the api folder.
- In the api folder just click on that folder right hand side you will get new after that file option you will get.
api -> New -> File
- Just create a file and whatever you generate the schema from JSON just paste that JSON Schema into that file.

- In Mule Palette you can Search JSON components or you can search in Search in Exchange JSON and add into the mule palette.
- Take Validate schema component from palette in anypoint studio.

- In the validation schema properties.In schema option you just call that JSON Schema which you created in the src/main/resources->api->secure.json.

- In secure.json file you can write the schema as well as you can you can add required field or mandatory field.

- In this I did a mandatory field.
“Required” : [
“Document_Type”,
“No”,
“CompanyName”
]
- Even you can do Error Handling
- You can take On-Error Propagate in that you can use Transform Message.
- In Transform message properties you can write.

- You will get a proper message if you missed any one of the fields that is required.
- If you pass all the body in POST Method with all fields you will get proper response.Success response 200 ( success code).

- Success response 200

- If I missed any one of the field
“Required” : [
“Document_Type”,
“No”,
“CompanyName”
]
In POST Method body.
I missed the “Document_Type”

- You will get 500 server Error Response.
- You will get the proper message which field you are missing.

Conclusion:
You can use the validate JSON and check from that JSON you can create JSON schema component from Mule palette.
References: