97008 48403
+91 40-27177600

Blog

How to replace the value in the json payload in Mule ESB?

single-blog

From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog introduces how to replace the value in the json payload in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.

From many situations we have seen in Mule ESB, we think replacing the value for binarycontent element with some string where the input and output are in JSON is worthy a discussion. Replacing this with some simple string “file content” for logging purpose as the binary content will take multiple pages to print. Lets consider an example where input and desired output are as follows:

Input: { “userId”: 1234, “userEmail”: “test@xyz.com”, “name”: “Test”, “documents”: [ { “binaryContent”: “VGVzdGluZyBEb2NNYW4gUkVTVCBBUEk=”, “comments”: “Hello Request”, “fileName”: “hello.pdf”, “documentType”: “General”, “attributes”: [ { “id”: 1, “name”: “Date Created”, “value”: “12/31/2020” }, { “id”: 2, “name”: “Version”, “value”: “V1” }] } ] }

Desired output: { “userId”: 1234, “userEmail”: “test@xyz.com”, “name”: “Test”, “documents”: [ { “binaryContent”: “file content”, “comments”: “Hello Request”, “fileName”: “hello.pdf”, “documentType”: “General”, “attributes”: [ { “id”: 1, “name”: “Date Created”, “value”: “12/31/2020” }, { “id”: 2, “name”: “Version”, “value”: “V1” }] } ] }

Here are the steps listed below:

Step 1:-Create a project and search http listener in Mule Palette and drag it to the message flow and configure as follows:

Step 2:- Keep the JSON to Object Transformer After the Http To convert JSON to object.

Step 3 : Drag an expression connector from mule Palette to message flow after the logger for looping the incoming json data.

Step 4:-Keep an expression in for each and write a Mule expression to replace the value in incoming Json.

Step 5:-Drag the Object to JSON transformer to print the JSON data to the output.

Step 6:- Complete flow is here.

Step 7:-Run the project and after successful deployment hit some data from postman to see the results

Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed the client need. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to info@massil.tech.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Get in touch with us

Scroll to top