0

I want to convert the below XML into JSON. Please suggest how to do in wso2 esb and what mediators to be used.

Input XML

<root>
  <tag1>LA - First Name , LA - Middle Name , LA - Last name</tag1>
  <tag1value>Sharath Kumar Chakali</tag1value>
</root>

Output JSON


{
  "LA - First Name , LA - Middle Name , LA - Last name" : "Sharath Kumar Chakali"
}
Community
  • 1
  • 1
  • Hello, welcome to Stackoverflow. For the next time please provide [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/minimal-reproducible-example). Basically - try to read the docs, try to do it yourself and ask when something unclear or not working. To be helpful - you may have a look at the [PayloadFactory](https://ei.docs.wso2.com/en/7.1.0/micro-integrator/references/mediators/payloadFactory-Mediator/) mediator – gusto2 Jun 26 '20 at 08:24
  • Here the xml comes from a DSS output, so we need to transform that DSS response into JSON as given in the sample example. So, I think PayloadFactory Mediator will not be useful since, the JSON field name and value has to be framed dynamically based on the XML Input – Priyanka Joseph Jun 26 '20 at 09:23
  • Then you have to transform DSS and return the json, That is not clear / different in the question – gusto2 Jun 26 '20 at 11:01
  • Basically, if my input xml is as given in the sample example, How to do I transform it to my expected JSON as given in the sample. In XML input, the fieldName "tag1" has value "LA - First Name , LA - Middle Name , LA - Last name" and fieldName "tag1value" has value "Sharath Kumar Chakali". So, how do I transform this dynamically in a way that the json fieldName will be the value of the field "tag1" from XML input and its value will be the value from "tag1value" – Priyanka Joseph Jun 26 '20 at 12:32

1 Answers1

0

This is not a standard transformation. Therefore what I can suggest is try to use a custom implementation for the mapping. You can either use a class mediator or a script mediator for this purpose. Please refer to the documentation on [1], [2] for this.

[1]-https://docs.wso2.com/display/EI610/Script+Mediator

[2]-https://docs.wso2.com/display/EI640/Class+Mediator