Layer7 API Management

Expand all | Collapse all

"Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

  • 1.  "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted Jul 25, 2017 08:26 PM

    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.



  • 2.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Broadcom Employee
    Posted Jul 27, 2017 06:56 PM

    Hello Rudra_Singh ,

    What version of gateway you have?

    Can you provide a sample xml ?

     

    Regards,

    Mark



  • 3.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted Jul 27, 2017 07:47 PM
      |   view attached

    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 "

    <Person><Surname>smith</Surname></Per

    son> " and the Json output is showing it as an object instead of an array.

     

    Json Output:

    {"Person":{"Surname":"smith"}}

     

    So it is missing square brackets

     

    Regards,

    Rudra Singh

    Attachment(s)



  • 4.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Broadcom Employee
    Posted Jul 27, 2017 08:01 PM

    Yes, this is the default behavior for single element, you may at least add an empty element to turn it to an array.



  • 5.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted Jul 27, 2017 08:21 PM

    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?

     

    Regards,

    Rudra Singh



  • 6.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.
    Best Answer

    Broadcom Employee
    Posted Jul 30, 2017 07:06 PM

    Hello Rudra,

    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)

     

    Regards,

    Mark



  • 7.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted Nov 22, 2017 07:15 AM

    Hi Rudra,

     

    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.

     

    Regards,

    Sonalee Shyam



  • 8.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted Nov 22, 2017 05:14 PM

    Hi Sonalee,

     

    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.

     

    Regards,

    Rudra Singh

    0470136257



  • 9.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted May 28, 2018 07:29 AM

    Hi Rudra,

     

    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.

     

    Please help.

     

    Thanks

    Nitin



  • 10.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted May 28, 2018 07:34 AM

    Hi Nitin,

     

    You can use regular expression assertion to remove the extra ""



  • 11.  Re: "Apply JSON Transformation" assertion is converting an Array of single element into Json Object instead of Array.

    Posted May 28, 2018 08:17 AM

    it worked. Thanks.