cancel
Showing results for 
Search instead for 
Did you mean: 

Converting XML to JSON using Content Modifier or Script

0 Kudos

Dear Experts,

I am having issue in Converting XML to JSON.

The format expected by Customer. Please let me know know how I can achieve it using Content modifier or Script.

I did some settings and got only first node of Customer and not able to get second and Subsequent nodes.

Please advise to fix the issue. The content Modifier screen shot is added in the attachmeny

Requested Output:

{
"name":"Lead time request Project",
"salesOrganisationName":"1000",
"number":"94895",
"Customers":[
{
"Country":"IN",
"HouseNumber":"3",
"Number":"100003535",
"PostalCode":"M3 2HW",
"Street":"Parsonage",
"CustomerType":"Installer",
"Name":"Adam Mcloughlin"
},
{
"Country":"LX",
"HouseNumber":"3",
"Number":"100003535",
"PostalCode":"M3 2HW",
"Street":"Parsonage",
"CustomerType":"Dealer",
"Name":"Adam Mcloughlin"
}
]
}

The Content Modifier Body I have user as below:

{
"name":"${property.name}",
"salesOrganisationName":"${property.salesOrganisationName}",
"number":"${property.number}",
"Customers":[
{
"Country":"${property.Country}",
"HouseNumber":"${property.HouseNumber}",
"Number":"${property.Number}",
"PostalCode":"${property.PostalCode}",
"Street":"${property.Street}",
"CustomerType":"${property.CustomerType}",
"Name":"${property.Name}"
}
]
}

After formatting with the above logic the the Output I received.

{
"name":"Lead time request Project",
"salesOrganisationName":"1000",
"number":"94895",
"Customers":[
{
"Country":"IN",
"HouseNumber":"3",
"Number":"100003535",
"PostalCode":"M32HW",
"Street":"Parsonage",
"CustomerType":"Installer",
"Name":"Adam Mcloughlin"
}
]
}

Thanks & Regards

capture.pngVijay S B

MortenWittrock
Active Contributor
0 Kudos

Hi Vijay

Please post your input XML as well. If you use the CODE formatting button, indentation is kept, which helps readability.

Regards,

Morten

Hi Morten,


Please find the input xml below

<?xml version="1.0" encoding="UTF-8"?><Root><name>Lead time request Project</name><salesOrganisationName>1000</salesOrganisationName><number>94895</number><Customers><Country>IN</Country><HouseNumber>3</HouseNumber><Number>100003535</Number><PostalCode>M3 2HW</PostalCode><Street>Parsonage</Street><CustomerType>Specifier</CustomerType><Name>Adam Mcloughlin</Name></Customers><Customers><Country>LX</Country><HouseNumber>3</HouseNumber><Number>100003535</Number><PostalCode>M3 2HW</PostalCode><Street>Parsonage</Street><CustomerType>Installer</CustomerType><Name>Adam Mcloughlin</Name></Customers></Root>

Thanks & regards

Vijay S B

0 Kudos

Hi Morten,

Thanks for the help. I already tried with XML to JSON Converter by Suppressing Root node and Streaming Customer node and it was working as expected. I wanted to check if it is any ways possible with Script or Content modifier. The receiver system is having some issues when I use XML to JSON Converter so wanted to try with Content modifier or Script. Hence while posting the blog I did specifically mention about Content modifier or Script since XML to JSON converter was working

Thanks & Regards

Vijay S B

MortenWittrock
Active Contributor
0 Kudos

Vijay,

I don't understand the problem - the generated output matches the requested output? If there is another issue in play, you obviously need to mention that. Otherwise community members put effort into answering the wrong question.

You can generate the same JSON output in a JavaScript or Groovy script, of course, but there is no reason to, based on the information you've provided.

You might need to signal to the receiving system, that you are, in fact, sending JSON data, by adding a Content-Type header with the value "application/json".

Regards,

Morten

Accepted Solutions (0)

Answers (1)

Answers (1)

aalapati
Explorer
0 Kudos

Hi Vijay,

I am having same requirement. Can you share the details how you acheived it.

Regards,

Aswini.