Layer7 API Management

Expand all | Collapse all

JSON Transform assertion changes the sequence of elements

  • 1.  JSON Transform assertion changes the sequence of elements

    Posted Apr 16, 2015 03:35 AM

    Hi,

     

    I am using the JSON transformation assertion to transform my JSON request to XML. But for a complex JSON object, the elements sequence gets changed. I have a given a simple example below for understanding. Does anyone know how to keep the sequence while transformation?

     

    Example JSON String

    "{ employee : { age:32, name : venugopal Darur,  employed:true}}";


    XMl String expected is


    <employee>

         <age>32</age>

         <name>Venugopal Darur</name>

        <employed>true</employed>

    </employee>


    But I get this:

    <?xml version="1.0" encoding="UTF-8"?>

    <Test>

        <employee>

            <name>venugopal Darur</name>

            <age>32</age>

            <employed>true</employed>

        </employee>

    </Test>

     

    Help is much appreciated.



  • 2.  Re: JSON Transform assertion changes the sequence of elements
    Best Answer

    Posted Apr 16, 2015 03:54 AM

    We have seen the same issue at one of our customers.

    Since the transformation can not create an ordered XML, we have used XSLT after the transformation to put the elements in the right order.



  • 3.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 16, 2015 04:29 AM

    I've created an Idea for it: JSON to XML transformation with ordered XML

    Please vote on it so they can consider it for a future version.



  • 4.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 16, 2015 05:32 PM

    Could you let me know how you used XLST transformation for putting the elements in the right order. Is this a generic solution? Since I have to do this for more then 10 different types of request, will I have to create a stylesheet for each type of request? If you can provide some example, it will be really helpful.



  • 5.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 11:06 AM

    It might be possible, but we didn't create a generic solution. If you have something like Altova, it's not too hard to create the mapping for each request.



  • 6.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 09:37 PM

    Thanks Michiel! I have created a stylesheet per request to make this working. Thanks for the solution and creating the idea. Hopefully we will see it implemented in the next versions.

     

    Thanks,

    Naren



  • 7.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 09:59 AM

    I'm curious as to why ordering would matter in the case of XML? Are you not able to extract the details you are needing?

    Whatever tool or code/policy that is expecting this XML message shouldn't be dependent on element ordering.

    Can you share your use case on why this is a requirement?

     

    thanks in advance!



  • 8.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 02:32 PM

    In this case the customer has an old backend which actually doesn't understand xml. There are (also old) services in front of them which take the xml and pass the parameters in order to the backend systems. The customer is aware that this is not an ideal solution and there is much room for improvement, but it is mostly out of their hands since those services are owned by various other departments.

     

    Since you can specify the order in a WSDL, in my opinion software like the gateway should be able to produce XML which conforms to those specifications.



  • 9.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 03:05 PM

    That's Fair...

     

    I have created an official Enhancement Request for the 'Apply JSON Transformation' Assertion, which is tracked with this id: SSG-11198



  • 10.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 03:11 PM

    Great, thanks. Is there any way we can track the progress on this, or could you update any progress in the Idea here: JSON to XML transformation with ordered XML

     

    Thanks,

    Michiel



  • 11.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 03:25 PM

    Im not sure of a direct way for you to view the status, but you can always open a Support Ticket in the future and they can look into it for you. I have voted on your idea as well, so I should be notified if comments are made on the Idea itself.

     

    The Product Management team will review enhancements and decide if, when, which future version to introduce the enhancement into.

     

    The more people that 'vote up' your idea, the more visibility it gets to Product Management.

     

    If it is brought into a new version, you should see a reference of it in the Release Notes.



  • 12.  Re: JSON Transform assertion changes the sequence of elements

    Posted Apr 17, 2015 09:49 PM

    Thanks Doyle for creating a Enhancement Request for this feature. Hopefully we will see something in the next release.

     

    Regards,

    Naren