JSON2XML policy is NOT working

I have applied JSON2XML policy, but it did NOT work

0 10 234
10 REPLIES 10

Not applicable

Ensure the content-type is application/json before the policy, then only it will be able to convert json to XML. I think you missed that.

From Develop tab, I am selecting Add Step -> Mediation -> JSON to XML. I do not see any provision to select content type there. Please advise.

to set the content type, you need one assign message policy as below before the JSON to XML Policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <Set>
        <QueryParams/>
        <FormParams/>
        <Payload/>
        <Headers>
         <Header name="Content_Type">application/json</Header>       </Headers>
    </Set>
    
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

make the below as response, if it's in the response flow. keep it "request" if it is in request flow.

 <AssignTo createNew="false" transport="http" type="request"/>

https://venkatagirivatlam-eval-test.apigee.net/venkatproxy this is my API proxy end point.

And I followed this youtube URL and it works pretty much fine without adding "Assign Message Policy

https://www.youtube.com/watch?v=ZtINy7n9QRc&list=PLIXjuPlujxxxe3iTmLtgfIBgpMo7iD7fk&index=3"

By the way, even after adding "Assing Message" policy JSON 2 XML is still NOT working.

Please advise, but the youtube URL mentioned above it just works fine by just adding the Json 2 xml policy. Strange... 🙂

Venkat, I’m sorry, I’m not at all clear on what you’re trying, or what you are explaining. You mentioned a YouTube url but did not cite it. You say you’re using AssignMessage but don’t give the configuration. You haven’t shown any configuration. Your messages are all assertions “it’s not working” but no context.


I’m sorry you’re having trouble, but We can’t help if you don’t provide specific details.

YouTube URL, I followed to apply JSON2XML policy -

https://www.youtube.com/watch?v=ZtINy7n9QRc&list=PLIXjuPlujxxxe3iTmLtgfIBgpMo7iD7fk&index=3

To verify the settings, policies and configuration, below is my API Proxy:

https://venkatagirivatlam-eval-test.apigee.net/venkatproxy

Yes I cannot see the YouTube url you are placing in your messages.

Also the url for your proxy... is also not something I can use. That looks like the url at which the proxy is listening. I can’t tell anything about how you’ve implemented the proxy from that url. I can’t see what you’ve done. You would have to show us that. Provide details.

Sorry I cannot help you.

Hey, I got it. The youtube URLs are getting filtered out.

Ok, I will provide the URL in double quotes ""

*******"

https://www.youtube.com/watch?v=ZtINy7n9QRc&list=PLIXjuPlujxxxe3iTmLtgfIBgpMo7iD7fk&index=3

"****

The most common reason people observe no output from the JSONToXML policy is... the content-type is not set properly on the inbound message. The JSONToXML policy will not transform a message, if the content-type header is not application/json or similar. Even if the actual payload is JSON, the policy first checks the header, and will "No-op" if the header does not indicate a JSON variant.

If this is not the problem you're having, We will need more specific details to be able to help you! a working proxy that shows what you see, would be best.

Hello all, it worked finally, but how??

Here it is:

1) As I am a newbie, I have applied JSON 2 XML policy in Request section and NOT in Response.

2) Assign Message policy need to added at Request level and include the Headers as below:

<Headers>
         <Header name="Content_Type">application/json</Header>       </Headers>

Thanks to the community and very big thank you to avatar imagePriyadarshi Ajitav Jena . The enjoyment started now....