Maintain order of properties in request payload (EPL scripts)

Hi Everyone,
I am currently writing EPL script that listens for measurements and, for each of this measurements, it sends POST request to a microservice deployed on Cumulocity. The problem is that some of the properties inside payload have to be in specific order.
Example of proper payload:

{
  ...
  "datapoint":
  [
    {
      "y1": "",
      "y2": "",
      "x1": "",
      "x2": ""
    }
  ],
  ...
}

Example of invalid payload (required order: y1->y2->x1->x2):

  ...
  "datapoint":
  [
    {
      "y1": "",
      "x2": "",
      "x1": "",
      "y2": ""
    }
  ],
  ...

Is it somehow possible to maintain the order of properties while sending the request?

Thank you in advance!

The JSON standard describes an object as ā€œā€¦ an unordered set of name/value pairs.ā€ (see: JSON) So an implementation that relies on this order is inherently non-standard. Iā€™d recommend rethinking this design.

If this microservice you are sending this data to is under your control, my first thought would be to make it independent of such non-standard JSON parsing requirements.

2 Likes

More specifically, there is also no way in EPL to enforce the order of elements here.

In general, I suggest following Philipps suggestion to make the microservice not rely on the order. If the order is important you could use an array instead of an object as arrays have an order. You would still need to change the microservice though.

1 Like