order of elements changed in json payload in Service Callout/Assign message,Json payload elements reshuffled in Service callout

sibijacob
Participant I

Hi,

The elements in a JSON payload (Assign Message/ServiceCallment) have their order changed.

Is there some way to avoid the order change. Is there any was to avoid the reordering in JSON.

Regards

Sibi

1 7 2,569
7 REPLIES 7

Hi Sibi

You are asking an interesting question; I'd like to understand more about where and how you are seeing re-ordering of elements. Can you give me more specifics?

You mentioned AssignMessage and ServiceCallout. Exactly how are you using these policies, and how do you observe that the order of elements in a JSON message changes ?

Please be as specific as you can. Provide a working example if possible.

sibijacob
Participant I

Hi Dino,

Thank you for your response..

Please find attached

screen shot and curl command snippet which shows order of the elements changed.

The target system responds with a failure as they validate the json against the XSD and expect the elements in correct sequence.

Please advice what is can be done. Can send you a sample of this if required

Regards,

Sibi

Attached the sample(jsonpayload-reordering-rev7-2018-04-04.zip) project where the toggling of json payload

Hi Sibi

In your screenshot I see two things.

  • a curl command
  • an Assign Message

Both of these are thing YOU specify. I think you are saying "When comparing the AssignMessage and the curl command, the order of elements is different ".

And if that is so, then... change the order of elements, in one or the other! You are in control of those things.

I must be missing something, because this seems really simple.

amitkumar2091
Participant III

@Dino I think he is taking about the curl command by apigee to target server

6706-jsonpayload.png

@Sibi Jacob

You cannot rely on the ordering of elements within a JSON object.

According to json specs http://www.json.org/

An object is an unordered set of name/value pairs

So JSON libraries are free to arrange the order as they see fit.

The library apigee is using for json to string and vice-versa conversion is arranging elements in reverse alphabetical order.

Even if you find a way to keep the object order maintained , the solution still going to be vulnerable to apigee version updates (In case they start using a different library in background).

Now coming to XSD verification , if we follow JSON specs , order of a JSON object element should not be verified , specially if payload is coming from external system.

is this in your control to change or configure target in such way or its an external system ?

I am not sure , if this is going to be of any help.

Ahhh, I see. Good catch. Thanks for the contribution.

sibijacob
Participant I

Thanks Amit for the feedback.