Using XmlToJSON Policy conversion with empty array

Hi, we have developed an api proxy in edge which receives the JSON payload from consumer and invokes the backed service after converting to xml.

Similarly the response from backend service is converted from XML to JSon using XMLToJSON policy.

As part of requirement, trying to convert an empty xml array element to JSON

Input: <Assets/>

After applying xml to JSON policy, it contains empty object;

"Assets": [ {} ],

Is there an option in apigee, perform conversion as an empty array [] rather than [{}].

Please advise.

0 3 293
3 REPLIES 3

I was able to reproduce the result you're getting of [{}] for an XML node with no children. I'd agree I'd expect to see [], however it doesn't seem to be possible to configure the XML to Json policy in such a way to generate this expected output.

It seems you would have to modify the result of the policy with another policy after.

Thanks @dane knezic for trying this out. Guess Javascript is an option, since the xml payload is huge just trying to refrain from using custom code. If you are aware of any other in-built policy to use please advise. Thanks again.

Can you show the XMLToJSON policy configuration, and the full message you are passing?