Layer7 API Management

 View Only
  • 1.  schema for the transition from xml to json

    Posted Sep 21, 2018 05:43 AM

    after transition from xml to json Syntax array missing Follw attach.



  • 2.  Re: schema for the transition from xml to json

    Broadcom Employee
    Posted Sep 23, 2018 09:07 PM

    Hello,

    It's expected.

    If only has one node/element in the payload, how can I tell it's an array, or just a normal node.

     

    Regards,

    Mark



  • 3.  Re: schema for the transition from xml to json

    Posted Sep 24, 2018 02:00 AM

    if array size = 1  ,how to you tell the element is array?

     

    Thank you



  • 4.  Re: schema for the transition from xml to json
    Best Answer

    Broadcom Employee
    Posted Sep 23, 2018 09:28 PM

    Yes, that is the case in a raw transformation it is not possible to determine that a single xml element is expected to be an array when transformed to json.  So simple transform can only transfer a single element as child json element not as an array.

     

    There is an idea/enhancement request  for the xml -> json transformation to use a json schema, to then be able to tell which resulting json elements should be an array: 

    https://communities.ca.com/ideas/235726359?commentID=233953278#comment-233953278 

     

    For a simple case where there is only one such element that needs to be an array, it might be possible to write some assertion code with regex and xml path replace/delete to force one element to be an array.  But the more complex case with many elements (perhaps identified by the "size" element in the xml structure it is not a realistic option. 

     

    An alternative perhaps simpler "Idea" to the one above would be to suggest the current assertion have an extra parameter that allows specification of list of JSON paths to be passed into the xml->json transformation assertion, and where matched they would generate a list even if only one element (and maybe option as well for when no elements are found).

     

    Other than that currently would need a custom assertion (written in java) - or change of the code accepting the JSON result to be to handle single result as well as array result. 

     

    Cheers - Mark

     



  • 5.  Re: schema for the transition from xml to json

    Posted Sep 24, 2018 02:02 AM

    Thank you