# JSON to xml code

**URL:** https://discourse.nodered.org/t/json-to-xml-code/94895
**Category:** FlowFuse
**Created:** [25 January 2025 06:36 UTC](https://discourse.nodered.org/t/json-to-xml-code/94895 "2025-01-25T06:36:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![imperium85](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imperium85/32/83662_2.png) [@imperium85](https://discourse.nodered.org/u/imperium85)
#### Post date: [25 January 2025 06:36 UTC](https://discourse.nodered.org/t/json-to-xml-code/94895/1 "2025-01-25T06:36:39Z")

</div>

Hi There,  
I have the following example XML code:

```auto
 <?xml version="1.0" encoding="UTF-8"?> 
<RequestCall>     
     <RequestName>TestDBUser.Insert</RequestName>
     <Params>         
<TestDBUser>             
 <ExtUserID>33333</ExtUserID>
 <FirstName>Peter</FirstName>             
 <LastName>NodeRed</LastName>             
 <Title>Mr</Title> 
 <UserExpiration.Enabled> 1 </UserExpiration.Enabled> 
 <UserExpiration> 2025-01-31 </UserExpiration> 
 <KeyExpirationDifferentFromUserExpiration> 1 </KeyExpirationDifferentFromUserExpiration> 
 <KeyRevalidation.UpdatePeriod> 3 </KeyRevalidation.UpdatePeriod> 
 <KeyRevalidation.UnitOfUpdatePeriod>0</KeyRevalidation.UnitOfUpdatePeriod>         
     </TestDBUser>
   </Params> 
</RequestCall>

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b03bef5e14748e2e5347afe91bfa0bb9ec71dbb3.png)

If I insert it in an inject node msg.payload and send it through the HTTP Request node, it works fine and creates the user in my 3rd Party system.  
But I will receive the name from an other system in JSON in a msg.username payload. How Can I insert this username into my xml code to make the First and LastName dynamic?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [25 January 2025 06:47 UTC](https://discourse.nodered.org/t/json-to-xml-code/94895/2 "2025-01-25T06:47:12Z")

</div>

There are multiple ways, but let's take an example inject node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/12bd534aa7893f35fa0e47e34fe853ce14b9760b.png)

Next use a template node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff0542d2e80c9d1bf2a645c653fe53aebe216cfd.png)

there you can use 'mustache' templates, so you can create a base template in xml and fill whatever details you want.

```auto
 <FirstName>{{payload.firstname}}</FirstName>             
 <LastName>{{payload.lastname}}</LastName>            

```

Output:

```auto
<?xml version="1.0" encoding="UTF-8"?> 
<RequestCall>     
     <RequestName>TestDBUser.Insert</RequestName>
     <Params>         
<TestDBUser>             
 <ExtUserID>33333</ExtUserID>
 <FirstName>John</FirstName>             
 <LastName>Doe</LastName>             
 <Title>Mr</Title> 
 <UserExpiration.Enabled> 1 </UserExpiration.Enabled> 
 <UserExpiration> 2025-01-31 </UserExpiration> 
 <KeyExpirationDifferentFromUserExpiration> 1 </KeyExpirationDifferentFromUserExpiration> 
 <KeyRevalidation.UpdatePeriod> 3 </KeyRevalidation.UpdatePeriod> 
 <KeyRevalidation.UnitOfUpdatePeriod>0</KeyRevalidation.UnitOfUpdatePeriod>         
     </TestDBUser>
   </Params> 
</RequestCall>

```

---

<div class="post-metadata">

### Author: ![imperium85](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/imperium85/32/83662_2.png) [@imperium85](https://discourse.nodered.org/u/imperium85)
#### Post date: [25 January 2025 06:50 UTC](https://discourse.nodered.org/t/json-to-xml-code/94895/3 "2025-01-25T06:50:03Z")

</div>

WOW, i did not think about this, I over killed it .  
Thank you very much!!!
