{"id":6898,"date":"2019-09-15T21:18:52","date_gmt":"2019-09-16T01:18:52","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6898"},"modified":"2019-09-15T21:20:06","modified_gmt":"2019-09-16T01:20:06","slug":"mulesoft-4-transformation-convert-json-to-xml","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/integration\/mulesoft\/mulesoft-4-transformation-convert-json-to-xml\/","title":{"rendered":"Mulesoft 4 Transformation &#8211; Convert JSON to XML"},"content":{"rendered":"\n<p>We will start creating Mule Project in Anypoint studio and input would be provided by Http Listener. <\/p>\n\n\n\n<p>Make sure MIME type of Http Listener set to application\/json, otherwise we will get below error :<\/p>\n\n\n\n<p><strong>Dataweave Error: You called the function &#8216;Value Selector&#8217; with these arguments &#8230; <\/strong><\/p>\n\n\n\n<p>Mulesoft Project structure below <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"255\" height=\"267\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/09\/Mulesoft-Project-Convert-JSON-to-XML.png?resize=255%2C267&#038;ssl=1\" alt=\"Mulesoft-Project-Convert-JSON-to-XML\" class=\"wp-image-6899\"\/><figcaption>Mulesoft  Project &#8211; Convert JSON to XML<\/figcaption><\/figure><\/div>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Method 1 : Simplest<\/strong><\/p>\n\n\n\n<p>Simplest way to convert JSON to XML is to just put payload as value in transformation component<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n%dw 2.0\noutput application\/xml\n---\n{\n\tProfiles: payload\n}\n<\/pre><\/div>\n\n\n<p>Input  (You can use Postman to make POST request on Http listener)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n{\n    &quot;Profiles&quot; : &#x5B;\n                    {\n                        &quot;name&quot;:&quot;John&quot;,\n                        &quot;LastName&quot; : &quot;Doe&quot;,\n                        &quot;Age&quot; : 30,\n                        &quot;Country&quot;:&quot;India&quot;,\n                        &quot;Profession&quot; : &quot;Salesofrce Architect&quot;,\n                        &quot;Skills&quot;:&quot;Salesforce, HTML&quot;\n                    },\n                    {\n                        &quot;name&quot;:&quot;Jenny&quot;,\n                        &quot;LastName&quot; : &quot;Doe&quot;,\n                        &quot;Age&quot; : 40,\n                        &quot;Country&quot;:&quot;USA&quot;,\n                        &quot;Profession&quot; : &quot;Mulesoft Architect&quot;,\n                        &quot;Skills&quot;:&quot;HTML, Mulesoft&quot;\n                    }\n                ]\n    }\n<\/pre><\/div>\n\n\n<p>Output<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;?xml version=&#039;1.0&#039; encoding=&#039;UTF-8&#039;?&gt;\n&lt;Profiles&gt;\n    &lt;Profiles&gt;\n        &lt;name&gt;John&lt;\/name&gt;\n        &lt;LastName&gt;Doe&lt;\/LastName&gt;\n        &lt;Age&gt;30&lt;\/Age&gt;\n        &lt;Country&gt;India&lt;\/Country&gt;\n        &lt;Profession&gt;Salesofrce Architect&lt;\/Profession&gt;\n        &lt;Skills&gt;Salesforce, HTML&lt;\/Skills&gt;\n    &lt;\/Profiles&gt;\n    &lt;Profiles&gt;\n        &lt;name&gt;Jenny&lt;\/name&gt;\n        &lt;LastName&gt;Doe&lt;\/LastName&gt;\n        &lt;Age&gt;40&lt;\/Age&gt;\n        &lt;Country&gt;USA&lt;\/Country&gt;\n        &lt;Profession&gt;Mulesoft Architect&lt;\/Profession&gt;\n        &lt;Skills&gt;HTML, Mulesoft&lt;\/Skills&gt;\n    &lt;\/Profiles&gt;\n&lt;\/Profiles&gt;\n<\/pre><\/div>\n\n\n<p>As you can see above, JSON converted to XML with almost same format. If it works for you then great. However you may want some flexibility on how final xml look like.<\/p>\n\n\n\n<p><strong>Method 2 &#8211; Changing format while conversion<\/strong><\/p>\n\n\n\n<p>If we want <em>lastName<\/em> and <em>age<\/em> as attribute of <em>name<\/em> node in xml, then we will need to play little bit with Dataweave2 as shown below<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n%dw 2.0\noutput application\/xml\n---\n{\n\tProfiles: {\n\t\t(payload.Profiles map ( person , indexOfPerson ) -&gt; {\n\t\t\tcandidates: {\n\t\t\t\tname @(lastName: person.LastName , age: person.Age): person.name,\n\t\t\t\tcountry: person.Country,\n\t\t\t\tProfession: person.Profession,\n\t\t\t\tSkills: person.Skills\n\t\t\t}\n\t\t})\n\t}\n}\n<\/pre><\/div>\n\n\n<p>Output :<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;?xml version=&#039;1.0&#039; encoding=&#039;UTF-8&#039;?&gt;\n&lt;Profiles&gt;\n    &lt;candidates&gt;\n        &lt;name lastName=&quot;Doe&quot; age=&quot;30&quot;&gt;John&lt;\/name&gt;\n        &lt;country&gt;India&lt;\/country&gt;\n        &lt;Profession&gt;Salesofrce Architect&lt;\/Profession&gt;\n        &lt;Skills&gt;Salesforce, HTML&lt;\/Skills&gt;\n    &lt;\/candidates&gt;\n    &lt;candidates&gt;\n        &lt;name lastName=&quot;Doe&quot; age=&quot;40&quot;&gt;Jenny&lt;\/name&gt;\n        &lt;country&gt;USA&lt;\/country&gt;\n        &lt;Profession&gt;Mulesoft Architect&lt;\/Profession&gt;\n        &lt;Skills&gt;HTML, Mulesoft&lt;\/Skills&gt;\n    &lt;\/candidates&gt;\n&lt;\/Profiles&gt;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Dataweave code to convert JSON to XML in Mulesoft 4<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[454],"tags":[473,457],"class_list":["post-6898","post","type-post","status-publish","format-standard","hentry","category-mulesoft","tag-dataweave2","tag-mulesoft-4"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":7741,"url":"https:\/\/www.jitendrazaa.com\/blog\/integration\/mulesoft\/salesforce-bulk-api-2-using-mulesoft\/","url_meta":{"origin":6898,"position":0},"title":"Salesforce Bulk API 2 using Mulesoft","author":"Jitendra","date":"November 20, 2022","format":false,"excerpt":"Demo of using Bulk API 2 & Solving most common errors","rel":"","context":"In &quot;Mulesoft&quot;","block_context":{"text":"Mulesoft","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/mulesoft\/"},"img":{"alt_text":"Bulk API 2 using MuleSoft","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Bulk-API-2-using-Mulesoft.png?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Bulk-API-2-using-Mulesoft.png?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Bulk-API-2-using-Mulesoft.png?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Bulk-API-2-using-Mulesoft.png?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Bulk-API-2-using-Mulesoft.png?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":30699,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/complete-mulesoft-guide-40-expert-interview-questions\/","url_meta":{"origin":6898,"position":1},"title":"Complete MuleSoft Guide: 40+ Expert Interview Questions &amp; Answers","author":"Jitendra Zaa","date":"December 18, 2025","format":false,"excerpt":"Master MuleSoft interviews with 40+ expert questions covering API-led connectivity, DataWeave, Kafka, Salesforce integration, AI capabilities (Agentforce, MAC Project), CloudHub deployment, VPC\/VPN security, certifications, and career paths. Includes Gartner iPaaS 2025 insights.","rel":"","context":"In &quot;Integration&quot;","block_context":{"text":"Integration","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/"},"img":{"alt_text":"Complete MuleSoft Guide - 40+ Expert Interview Questions covering API-Led Connectivity, DataWeave, Agentforce AI, CloudHub VPC, Certifications, Career Path, Kafka Integration, and Gartner iPaaS 2025","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2025\/12\/mulesoft-interview-questions-2025-featured-new.png?fit=1200%2C704&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2025\/12\/mulesoft-interview-questions-2025-featured-new.png?fit=1200%2C704&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2025\/12\/mulesoft-interview-questions-2025-featured-new.png?fit=1200%2C704&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2025\/12\/mulesoft-interview-questions-2025-featured-new.png?fit=1200%2C704&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2025\/12\/mulesoft-interview-questions-2025-featured-new.png?fit=1200%2C704&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":6863,"url":"https:\/\/www.jitendrazaa.com\/blog\/integration\/mulesoft\/mulesoft-live-demo-alpharetta-developer-group-meet\/","url_meta":{"origin":6898,"position":2},"title":"Introduction to Mulesoft with Example &#8211; Alpharetta Developer Group Meet","author":"Jitendra","date":"June 17, 2019","format":false,"excerpt":"Slides and Video from Alpharetta Developer group meet - Loading data in Salesforce using Mulesoft 4","rel":"","context":"In &quot;Mulesoft&quot;","block_context":{"text":"Mulesoft","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/mulesoft\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/sqWLC2I8Ozg\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6752,"url":"https:\/\/www.jitendrazaa.com\/blog\/integration\/mulesoft\/defining-pipe-delimited-separator-in-mulesoft-3-4\/","url_meta":{"origin":6898,"position":3},"title":"Defining pipe delimited separator in Mulesoft 3 &#038; 4","author":"Jitendra","date":"January 24, 2019","format":false,"excerpt":"How to use Pipe delimiter as separator in Mulesoft 3 and 4","rel":"","context":"In &quot;Mulesoft&quot;","block_context":{"text":"Mulesoft","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/mulesoft\/"},"img":{"alt_text":"Reader Configuration in Transform Message - Mulesoft 3","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Reader-Configuration-in-Transform-Message-Mulesoft-3.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":6739,"url":"https:\/\/www.jitendrazaa.com\/blog\/integration\/process-pipe-delimited-file-in-mulesoft-3\/","url_meta":{"origin":6898,"position":4},"title":"Use pipe delimited file to upsert record in Mulesoft 3","author":"Jitendra","date":"January 24, 2019","format":false,"excerpt":"Use Mulesoft to upsert record in Salesforce using Pipe delimited file","rel":"","context":"In &quot;Integration&quot;","block_context":{"text":"Integration","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/"},"img":{"alt_text":"Upsert record in Salesforce using Mulesoft","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2019\/01\/Upsert-record-in-Salesforce-using-Mulesoft.png?fit=500%2C215&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7731,"url":"https:\/\/www.jitendrazaa.com\/blog\/integration\/mulesoft\/working-with-postgresql-on-mac-locally\/","url_meta":{"origin":6898,"position":5},"title":"Working with PostgreSQL on Mac locally","author":"Jitendra","date":"November 16, 2022","format":false,"excerpt":"This post walkthrough installing PostgreSQL, PGAdmin, starting & stopping service as need and Mulesoft tips","rel":"","context":"In &quot;Mulesoft&quot;","block_context":{"text":"Mulesoft","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/integration\/mulesoft\/"},"img":{"alt_text":"Working with PostgreSQL on Mac locally","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Working-with-PostgreSQL-on-Mac-locally.png?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Working-with-PostgreSQL-on-Mac-locally.png?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Working-with-PostgreSQL-on-Mac-locally.png?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2022\/11\/Working-with-PostgreSQL-on-Mac-locally.png?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=6898"}],"version-history":[{"count":2,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6898\/revisions"}],"predecessor-version":[{"id":6901,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6898\/revisions\/6901"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}