JSON Module Component in Mule 4

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.


validatejson flow scheduler read logger validate json schema on error propagate type json schema not honoured write logger

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:


src main resources application types log4j2 api examples document json schemas myschema json

The document.json file looks like this:


document json employeeid employeename

The schema against which the document.json file would be validated is defined as below:


myschema json schema type array items type object properties employeeid type string minlength 4 maxlength 6 employeename type string minlength 1 maxlength 255 required employeeid employeename
<