Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.
Is there any way to make it an array?
Or can we get an array withy empty elements added to single element array and remove it in Gateway, so that Gateway assertion assume it an array?
Is it good to go ahead with self created Custom Java assertion in Gateway.
If yes, please let us know.
Hello Rudra_Singh ,
What version of gateway you have?
Can you provide a sample xml ?
Hi @Zhijun He,
The version we are using is CA API Gateway 9.2.0.
I have attached the sample XML inpurt and the JSON output.
XML has a single element (Surname) in an array "
son> " and the Json output is showing it as an object instead of an array.
So it is missing square brackets
Yes, this is the default behavior for single element, you may at least add an empty element to turn it to an array.
Hi Zhijun He ,
Yes, I understand the workaround solution to add empty element in such case.
But what if the payload is complex and it has many such single element array in request. It will make the logic bit difficult.
Also is there any fix or case raised for this issue?
I don't think such kind of transformation can be done automatically, as the single element in the xml cannot tell it's an array or not.
You may need to manually verify the transformation result. (regular expression assertion should help)
Could you tell me how did you resolve this issue,we are facing similar issue with JSON Array.
We need to aggregate multiple JSON Response and only way to do this as i understand is using JSON->XML ->JSON transformation.
But the final response does not retain the array structure incase of single element.
XML to JSON transformation in API Gateway is not able to handle this scenario. The only way is to add "empty element" to an array with single element at the front end and then remove it in the Gateway using regular expression.
I am also facing same issue. When I added an extra empth element then transfromed that too in json. I am getting ,"" extra in json. Now how can I remove that? Since this json is rejected by backend.
You can use regular expression assertion to remove the extra ""
it worked. Thanks.