Ani

Ani

  • 169
  • 11.2k
  • 34.5k

Converting XML values to JSON aaray

Feb 11 2021 6:53 AM
Hi,

I have below xml which has to be converted to JSON array using xslt. Please help me
Input xml
<employee>
<empid>123</empid>
<empdesignation>MGR</empdesignation>
<emprole>employee,supervisior,manager</emprole>
<address>
<addressLine1>123 TEST LANE</addressLine1>
<addressLine2></addressLine2>
<cityName>BOSTON</cityName>
<countryName>USA</countryName>
<postalCode>07723</postalCode>
</address> 
</employee>
<company>
<companylocationid>2</companylocationid> 
<companylocation>USA</companylocation>
<address>
<addressLine1>789 WORK LANE</addressLine1>
<addressLine2></addressLine2>
<cityName>California</cityName>
<countryName>USA</countryName>
<postalCode>90210</postalCode> 
</address>
</company>
 
Expected JSON 
{
"employee":[
{
"empid":"123",
"empdesignation":"MGR",
"emprole": [
"employee,supervisior,manager"
],
"address":{
"addressLine1":"123 TEST LANE",
"addressLine2":"AddressLine2",
"cityName":"BOSTON",
"countryName":"USA",
"postalCode":"07723"
}
}
],
"company":[
{
"companylocationid":"2",
"companylocation":"USA",
"address":{
"addressLine1":"789 WORK LANE",
"addressLine2":"AddressLine2",
"cityName":"California",
"countryName":"USA",
"postalCode":"90210"
}
}
],
}

 

Answers (5)