SlideShare a Scribd company logo
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": “Big Boss",
"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>
Transformation jsontojsonesb

More Related Content

Viewers also liked

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

Viewers also liked (14)

Muleesbobjecttojson
Muleesbobjecttojson Muleesbobjecttojson
Muleesbobjecttojson
 
Mule esb expression_filter
Mule esb expression_filterMule esb expression_filter
Mule esb expression_filter
 
Consuming raml
Consuming ramlConsuming raml
Consuming raml
 
Transformation jsontoxmlesb
Transformation jsontoxmlesbTransformation jsontoxmlesb
Transformation jsontoxmlesb
 
Upserve Full
Upserve FullUpserve Full
Upserve Full
 
Slideshare
SlideshareSlideshare
Slideshare
 
ScalverleyResume
ScalverleyResumeScalverleyResume
ScalverleyResume
 
Mule esb collection_splitter
Mule esb collection_splitterMule esb collection_splitter
Mule esb collection_splitter
 
slideshare
slideshareslideshare
slideshare
 
Mule esb json_to_object
Mule esb json_to_objectMule esb json_to_object
Mule esb json_to_object
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
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 Transformation jsontojsonesb

Transformation jsontojsonesb
Transformation jsontojsonesbTransformation jsontojsonesb
Transformation jsontojsonesb
Germano Barba
 
Json to json transformation in mule
Json to json transformation in muleJson to json transformation in mule
Json to json transformation in mule
Antonio Pellegrino
 
Xml to xml transformation
Xml to xml transformationXml to xml transformation
Xml to xml transformation
Son Nguyen
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
mdfkhan625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
Mohammed625
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
Rajkattamuri
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
javeed_mhd
 
Xml transform
Xml transformXml transform
Xml transform
Son Nguyen
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
Davide Rapacciuolo
 
Mule xml transformation
Mule xml transformationMule xml transformation
Mule xml transformation
D.Rajesh Kumar
 
Xml toobjectesbtransform
Xml toobjectesbtransformXml toobjectesbtransform
Xml toobjectesbtransform
Domenico Schiavone
 
Transform json to json
Transform json to jsonTransform json to json
Transform json to json
Son Nguyen
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
Antonio Pellegrino
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
Germano Barba
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
Davide Rapacciuolo
 
Json
JsonJson
Json
manavp
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
Davide Rapacciuolo
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
javeed_mhd
 
Transforming with custom transformer in mule
Transforming with custom transformer in muleTransforming with custom transformer in mule
Transforming with custom transformer in mule
Praneethchampion
 
Converting with custom transformer
Converting with custom transformer Converting with custom transformer
Converting with custom transformer
mdfkhan625
 

Similar to Transformation jsontojsonesb (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
 
Transform json to json
Transform json to jsonTransform json to json
Transform json to json
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Transformation xmltoobjectesb
Transformation xmltoobjectesbTransformation xmltoobjectesb
Transformation xmltoobjectesb
 
Json
JsonJson
Json
 
Xml to xml transformation in mule
Xml to xml transformation in muleXml to xml transformation in mule
Xml to xml transformation in mule
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
 
Transforming with custom transformer in mule
Transforming with custom transformer in muleTransforming with custom transformer in mule
Transforming with custom transformer in mule
 
Converting with custom transformer
Converting with custom transformer Converting with custom transformer
Converting with custom transformer
 

More from Davide Rapacciuolo

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

More from Davide Rapacciuolo (14)

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
 
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

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 

Recently uploaded (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 

Transformation jsontojsonesb

  • 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": “Big Boss", "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