XML to JSON conversion

Four Stars

XML to JSON conversion

Hello Everyone,

I have one xml as input having multiple nested elements and I need to convert that xml into JSON document to load it into Couchbase using Talend. Below is my sample XML document.

<?xml version='1.0' encoding='UTF-8'?>
<xml>
<entities>
<entity id="5" version="123456">
<name>ABC</name>
<listCode>OF</listCode>
<address>MH INDIA</address>
<address>GJ INDIA</address>
<cd name="ID">1234</cd>
<cd name="SRC">XYZ</cd>
</entity>
</entities>
</xml>

Expected output:
"entity":{
"id":"5",
"version":"123456",
"name":"ABC",
"listCode":"OF",
"address": [{address1:"MH INDIA"},{address2:"GJ INDIA"}]
"sdf":[
{
"sdfvalue":"1234",
"sdfname":"ID"
},
{
"sdfvalue":"XYZ",
"sdfname":"Src"
}
]
}

I am getting output as 2 different JSON document, one for combination of "sdfvalue":"1234","sdfname":"ID" and second document for combination of "sdfvalue":"XYZ","sdfname":"Src"  like below....

"entity":{
"id":"5",
"version":"123456",
"name":"ABC",
"listCode":"OF",
"address": [{address1:"MH INDIA"},{address2:"GJ INDIA"}]
"sdf":[
{
"sdfvalue":"1234",
"sdfname":"ID"
}
]
}

"entity":{
"id":"5",
"version":"123456",
"name":"ABC",
"listCode":"OF",
"address": [{address1:"MH INDIA"},{address2:"GJ INDIA"}]
"sdf":[
{
"sdfvalue":"XYZ",
"sdfname":"Src"
}
]
}

I want output in single JSON document. Can anyone suggest me few ideas to implement it in Talend.

Eight Stars

Re: XML to JSON conversion

Please check out tXmlToJson custom component in talend exchange center.

https://exchange.talend.com/#marketplaceproductoverview:marketplace=marketplace%252F1&p=marketplace%...

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.