Samples on json to xml and vice-versa conversion in apigee using javascript or javacallout .

vermagovind92
Participant III

I have a usecase where I need to do json to xml and xml to json conversion using javascript in Apigee.

Could someone please provide me with samples on this?

How many policies i need to attach?

Samples on json to xml and vice-versa conversion in apigee using javascript or javacallout .

Note : I don't want to perform this task using XMLTOJSON and XMLTOJSON policy.

@anilsagar,@dinu

0 7 257
7 REPLIES 7

I know you've said you don't want to use the out of the box conversion policies... but why do you want to reinvent the wheel? If these policies don't give you the result you're after, you can always tweak their behaviour with their many configuration parameters, and, if after that you're still not getting what you need, then consider manipulating the result with some custom xslt, javascript or java code. It'll be a lot less painful.

thanks for your reply.

I don't want to perform this task using XMLTOJSON and XMLTOJSON policy.

Why not?

Hi Thanks for your reply ,

This is the requirement i got , where i need to convert the Xml request to Json response and Json request to Xml response with the help of JavaScript. Sample scenario i mentioned below. could you please provide me with samples for this or any reference, i have been used the StackOverFlow step, but unfortunately it's doesn't works for me. And i have been used the TagetEndpoint and NoTarget both but in PostMan i'm getting error.

Note : I don't want to perform this task using XMLTOJSON and XMLTOJSON policy.

If my xml request is:

<employees>
<employee>
<firstName>Govind</firstName><lastName>Verma</lastName>
</employee>
<employee>
<firstName>Amit</firstName><lastName>Kumar</lastName>
</employee>
</employees>

then i got json response as :

{"employees":[
{ "firstName":"Govind", "lastName":"Verma" },
{ "firstName":"Amit", "lastName":"Kumar" }
]}

And similarly vice-versa for this.(json to xml).

Thanks & Regards

Govind Verma

I don't want to perform this task using XMLTOJSON and XMLTOJSON policy.

You're not answering the question.

Why not?

Actually i'm new in Apigee , I got a task where I need to perform this operation with the help of javascript.

I'd suggest you have a chat with whoever assigned this task to you, and explain why it would make sense to use the out of the box policies. As I said before, why reinvent the wheel?