How can i convert Xml data to Json and Json to Xml using Extract Variable or Assign Message Policy?

Hi Team,

I have a usecase where I have to convert my Response Content data to "JsonToXml and XmlToJson" using the Extract variable policy or Assign message Policy.

Is it Posiible?

Could Someone please help me out?

Thanks in Advance.
Rishika

@Anil Sagar @ Google,@Anil Sagar,@Siddharth Barahalikar,@Dino-at-Google,@sudheendras,

@Dino,@brandon@apigee.com,@Brendan,@Kuldeep Bhati,@deboraelkin,@Nagashree B,

@Debashish Roy,@Priyadarshi Ajitav Jena,@Mukundha Madhavan,@Abhishek Subramanya,

@arghya das

0 3 492
3 REPLIES 3

Neither ExtractVariable(EV) nor Assign message(AM) policies are directly used for data transformations.

Well, you can use ExtractVariable(EV) policy to manually extract each variable and create a custom XML/JSON Payload using Assign message(AM).

But why use EV and AM policies for data transformations? It is an anti-pattern. Make use of the OOTB JsonToXml and XmlToJson policies?

Hi @Siddharth Barahalikar,

Thank you for your time,

I have already did this task by the use of the OOTB JsonToXml and XmlToJson policies.

But I want to perform same task with the help of Extract variable policy and Assign message Policy.

And In my Response Content I'm getting my response data. And I want to convert it as json if response data is as xml and vice versa.

And I used Extract Variable policy at the TargetEnd Point Response .


Not clear.

It sounds like you are saying:

"I want to row across the pond. I've already done it in my boat with oars. Now I want to do it floating on a lawn chair and padding with garden rakes."

Why do you want to use a lawnchair and garden rakes to paddle across a pond? The XMLToJSON and JSONToXML policies do exactly what you want; they convert from JSON to XML and vice versa. These are the boat and oars. The AssignMessage and ExtractVariables do not convert from XML to JSON and JSON to XML . That's not what they do. If you want to convert from JSON to XML, these policies are the lawn chair and garden rake.

Put down the rake. Get back in the boat. Pick up the oars. Your problem is solved.