Updated: Sep 4
Github repository with the Mule Project can be found at the end of the post.
The JSON Module Connector is used to validate a JSON Payload against the predefined JSON Schema of your choice. Since schema validation falls outside the scope of DataWeave Functionality, the JSON Module can be used.
To use the JSON module, add it manually to your Mule app in Anypoint Studio or Design Center; or, if you want to use Maven, you can add the following dependency into your pom.xml file:
<dependency> <groupId>org.mule.modules</groupId> <artifactId>mule-json-module</artifactId> <version>RELEASE</version> <classifier>mule-plugin</classifier> </dependency>
For better understanding of how the JSON Module works, I did a proof of Concept. Below is the screenshot of the flow which includes the JSON Module component.
To validate the JSON payload, I need an example JSON file (in my case, document.json) and I would need the JSON schema file (mySchema.json) to validate my example JSON file against it. Since I chose to read the document.json file, I placed it below src/main/resources/examples:
The document.json file looks like this:
The schema against which the document.json file would be validated is defined as below: