SlideShare a Scribd company logo
1 of 10
JSON to JSON transformation in Mule
We often deals with JSON payloads in our
application on a large scale, specially whenever
we are exposing or consuming a REST API. One of
the common scenario we get is to modify or
transform the input JSON payload to another JSON
format and produce it as an output.
if we consider the following
{
"name": “Mike White",
"id": 37
}
This is a simple JSON payload taken as an example,
which contains only 2 elements, that
is name and id.
So, if this JSON payload is coming into our
application as an input and we require to
transform/modify the payload into another JSON format
and produce it as an output, something like the following
{
"name": "John Rosso",
"id": 37,
"designation": "Director"
}
Where you can see the modified JSON has a new
element designation as a third
element. The challenge here is to modify the
existing input JSON payload and to design an output JSON
payload from it, which will contain this additional
element in it with the same format. So, the question is,
how can be the input JSON format can be modified or
transformed in another JSON format that we require, in
a Mule application ??
The answer is Mule has a rich set of transformers and
offers different options to transform form one format of
payload into another. Mule also offers a powerful
component called Datamapper, which is limited to Mule
enterprise edition, and that can perform all these
requirement in easy way.
But here for Mule community edition, we will choose a
simplest way of doing it. We will be
using Expression Transformer for doing this.
Here is the following Mule flow, where we can
transform the JSON input into another JSON format.
So, you can transform from one JSON to another
dynamically using Expression transformer in the
following flow.
<flow name="DynamicJSONFlow1" doc:name="DynamicJSONFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost"
port="8085" path="test" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.lang.Object"
doc:name="JSON to Object"/>
<set-variable variableName="name" value="#[message.payload.name]"
doc:name="Variable"/>
<set-variable variableName="id" value="#[message.payload.id]"
doc:name="Variable"/>
<expression-transformer
expression="#[[
'name':flowVars.name,
'id':flowVars.id,
'designation':'Designation'
]
]" doc:name="Expression"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger level="INFO" message="#[message.payload]"
doc:name="Logger"/>
</flow>
Enjoy with the Mule!

More Related Content

Viewers also liked (14)

ScalverleyResume
ScalverleyResumeScalverleyResume
ScalverleyResume
 
Transformation jsontoxmlesb
Transformation jsontoxmlesbTransformation jsontoxmlesb
Transformation jsontoxmlesb
 
Mule esb json_to_object
Mule esb json_to_objectMule esb json_to_object
Mule esb json_to_object
 
Consuming raml
Consuming ramlConsuming raml
Consuming raml
 
Upserve Full
Upserve FullUpserve Full
Upserve Full
 
Slideshare
SlideshareSlideshare
Slideshare
 
slideshare
slideshareslideshare
slideshare
 
Mule esb expression_filter
Mule esb expression_filterMule esb expression_filter
Mule esb expression_filter
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Mule esb collection_splitter
Mule esb collection_splitterMule esb collection_splitter
Mule esb collection_splitter
 
Muleesbobjecttojson
Muleesbobjecttojson Muleesbobjecttojson
Muleesbobjecttojson
 
herramientas de la web 2.0
herramientas de la web 2.0herramientas de la web 2.0
herramientas de la web 2.0
 
Mule esb soap_service
Mule esb soap_serviceMule esb soap_service
Mule esb soap_service
 
Presentacion bitacora
Presentacion bitacoraPresentacion bitacora
Presentacion bitacora
 

Similar to Json to json transformation in mule

Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesbGermano Barba
 
Json to json transformation in mule
Json to json transformation in muleJson to json transformation in mule
Json to json transformation in muleAntonio Pellegrino
 
Xml to xml transformation
Xml to xml transformationXml to xml transformation
Xml to xml transformationSon Nguyen
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mulemdfkhan625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleRajkattamuri
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mulejaveed_mhd
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleMohammed625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in muleDavide Rapacciuolo
 
Mule xml transformation
Mule xml transformationMule xml transformation
Mule xml transformationD.Rajesh Kumar
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesbGermano Barba
 
Transform json to json
Transform json to jsonTransform json to json
Transform json to jsonSon Nguyen
 
Creating dynamic json
Creating dynamic json Creating dynamic json
Creating dynamic json mdfkhan625
 
Creating dynamic json
Creating dynamic jsonCreating dynamic json
Creating dynamic jsonHasan Syed
 
Creating dynamic json in mule
Creating dynamic json in muleCreating dynamic json in mule
Creating dynamic json in mulePraneethchampion
 
Creating dynamic json
Creating dynamic json Creating dynamic json
Creating dynamic json Khasim Saheb
 

Similar to Json to json transformation in mule (20)

Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesb
 
Json to json transformation in mule
Json to json transformation in muleJson to json transformation in mule
Json to json transformation in mule
 
Xml to xml transformation
Xml to xml transformationXml to xml transformation
Xml to xml transformation
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Xml transform
Xml transformXml transform
Xml transform
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Mule xml transformation
Mule xml transformationMule xml transformation
Mule xml transformation
 
Xml toobjectesbtransform
Xml toobjectesbtransformXml toobjectesbtransform
Xml toobjectesbtransform
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transform json to json
Transform json to jsonTransform json to json
Transform json to json
 
Json
JsonJson
Json
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Creating dynamic json
Creating dynamic json Creating dynamic json
Creating dynamic json
 
Creating dynamic json
Creating dynamic jsonCreating dynamic json
Creating dynamic json
 
Creating dynamic json in mule
Creating dynamic json in muleCreating dynamic json in mule
Creating dynamic json in mule
 
Creating dynamic json
Creating dynamic json Creating dynamic json
Creating dynamic json
 

More from Davide Rapacciuolo (15)

Mule esb db_2
Mule esb db_2Mule esb db_2
Mule esb db_2
 
Mule esb db_1
Mule esb db_1Mule esb db_1
Mule esb db_1
 
Transf from csv to xml
Transf from csv to xmlTransf from csv to xml
Transf from csv to xml
 
Esb choice flow
Esb choice flowEsb choice flow
Esb choice flow
 
Transformation csvtoxml
Transformation csvtoxmlTransformation csvtoxml
Transformation csvtoxml
 
Rest fullservices
Rest fullservicesRest fullservices
Rest fullservices
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Mule esb object_to_json
Mule esb object_to_jsonMule esb object_to_json
Mule esb object_to_json
 
Mule esb object_to_jackson_json
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_json
 
Transformation jsontoxmlesb
Transformation jsontoxmlesbTransformation jsontoxmlesb
Transformation jsontoxmlesb
 
Mule esb csv_to_json
Mule esb csv_to_jsonMule esb csv_to_json
Mule esb csv_to_json
 
Mule esb object_to_json
Mule esb object_to_jsonMule esb object_to_json
Mule esb object_to_json
 
Mule esb file to-string flow
Mule esb file to-string flowMule esb file to-string flow
Mule esb file to-string flow
 
My mule esb first http flow
My mule esb first http flowMy mule esb first http flow
My mule esb first http flow
 
My mule esb flow
My mule esb flowMy mule esb flow
My mule esb flow
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Json to json transformation in mule

  • 1. JSON to JSON transformation in Mule
  • 2. We often deals with JSON payloads in our application on a large scale, specially whenever we are exposing or consuming a REST API. One of the common scenario we get is to modify or transform the input JSON payload to another JSON format and produce it as an output.
  • 3. if we consider the following { "name": “Mike White", "id": 37 } This is a simple JSON payload taken as an example, which contains only 2 elements, that is name and id.
  • 4. So, if this JSON payload is coming into our application as an input and we require to transform/modify the payload into another JSON format and produce it as an output, something like the following { "name": "John Rosso", "id": 37, "designation": "Director" }
  • 5. Where you can see the modified JSON has a new element designation as a third element. The challenge here is to modify the existing input JSON payload and to design an output JSON payload from it, which will contain this additional element in it with the same format. So, the question is, how can be the input JSON format can be modified or transformed in another JSON format that we require, in a Mule application ??
  • 6. The answer is Mule has a rich set of transformers and offers different options to transform form one format of payload into another. Mule also offers a powerful component called Datamapper, which is limited to Mule enterprise edition, and that can perform all these requirement in easy way.
  • 7. But here for Mule community edition, we will choose a simplest way of doing it. We will be using Expression Transformer for doing this. Here is the following Mule flow, where we can transform the JSON input into another JSON format. So, you can transform from one JSON to another dynamically using Expression transformer in the following flow.
  • 8. <flow name="DynamicJSONFlow1" doc:name="DynamicJSONFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8085" path="test" doc:name="HTTP"/> <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> <set-variable variableName="name" value="#[message.payload.name]" doc:name="Variable"/> <set-variable variableName="id" value="#[message.payload.id]" doc:name="Variable"/> <expression-transformer
  • 10. Enjoy with the Mule!