Hey Readers, It's been a long time since I posted a blog again! But believe me I just came up with an interesting topic. I am sure at one or the other point it will be useful! 😀
Do you know that we can map the data and convert it to json format without using palette options?
🤔 Obviously yes!
In this blog lets see about how to map the data and convert back to json format without using the message mapping and converters in integration flow.
Of course, I am not very good at coding 😅 but yes! I follow some simple tricks to make our work easy in our day to day life.
Objective:
Map the incoming data to target structure and convert back to JSON format using Groovy Script.
Source Structure:
{ "id": "456783421908765z", "time": "2025-01-13T08:25:37.066663700Z", "data": { "moduleName": "Create", "firstName": "SAP", "lastName": "CPI", "startDate": "02/16/2025", "endDate": "03/31/2025", "code": "1234" } } |
Target Structure:
{ "uniqueID": "456783421908765z" ,"module": "Create", "fName": "SAP", "lName": "CPI", "startDate": "02/16/2025", "endDate": "03/31/2025" } |
Integration Flow Details:
Step1: Lets build a simple integration flow by adding a groovy script.
Step2: For capturing the incoming payload lets create a property in the content modifier. If the value is true then capture the payload else not.
Step3:
Ah! Our most important code in this blog... Lets add some pieces of code to do mapping in groovy without using palette options.
def Message processData(Message message) //get properties //log input payload //extract data from the json def id = jsonMsg.id; //construct Target payload jbuilder output_payload = jslurpur.parseText(jbuilder.toString()); } |
Execution:
Finally, Its time to execute! I have executed the code by using groovy IDE.
Tadaaa! The Output is here! 🤗
You can also see the input payload attached on the bottom right side of the page under
'Attachments'.
Okay then, I hope this blog is informative! Let's catch up on the next blog.
please feel free to drop a comment and don't forget to follow me on linkedin
Mounika - Linkedin
Thanks & Regards,
Mounika.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 47 | |
| 31 | |
| 22 | |
| 20 | |
| 18 | |
| 10 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |