Products Resources Support About Us

REST server reformatting outgoing JSON payload

Hello,

We are using the U2 rest server to call a UV subroutine. The subroutine has two parameters, Input and Output and both are configured as JSON parameters in the U2 Restful Service configuration.This subroutine accepts an incoming JSON payload and builds a reply JSON payload using UDO.
The output payload looks like this after built by the subroutine and this is what gets returned in the outgoing parameter:

 {
    	"json-rpc": "2.0",
    	"id": "103829839-383838",
    	"pagination": [
    		{
    			"total": "1"
    		}
    	],
    	"result": [
    		{
    			"auth_token": "xyz"
    		}
    	]
    }

When the client (in this case Postman) receives the reply it looks like this:

{
  "OutputPayload": {
    "result": [
      {
        "auth_token": "abc"
      }
    ],
    "pagination": [
      {
        "total": "1"
      }
    ],
    "json-rpc": "2.0",
    "id": "103829839-383838"
  }
}

We have been trying to establish a pattern. This is a simple message and it seems to be sorted alphabetically in descending order, but in more complex payloads there seems to be no pattern.

Has anyone encountered this before and is there a way to keep the JSON payload intact ?

I have never worried about the order. The order of the named value pairs does not matter to JSON. I guess you could switch it to a string, and it would not change, but then it would not be JSON.

Note the spec for JSON: https://tools.ietf.org/html/rfc7159 states in the introduction:
"An object is an unordered collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array.

An array is an ordered sequence of zero or more values."

Hope this helps.

Mike Rajkowski