conductor icon indicating copy to clipboard operation
conductor copied to clipboard

JSON_JQ_TRANSFORM - Incorrect fields sorting in the result

Open grmi-developer opened this issue 3 years ago • 0 comments

Problem:

JSON_JQ_TRANSFORM executes my queryExpression correctly but the transformed json has the fields sorted by the JSON_JQ_TRANSFORM but not by the JQ queryExpression .

Previous task result (Json input to the next task):

"body": {
      "data": {
        "customer": {
          "id": "6390dda34b1a9e9449a05c3e",
          "name": "Jack",
          "surname": "Jons",
          "email": "test",
          "phone": "32424242",
          "customerType": "INDIVIDUAL",
          "customerStatus": "ACTIVE",
          "addresses": [
            {
              "id": "6394a00022ffce77649b15ee",
              "city": "London",
              "street": "Yellow st.",
              "home": "43",
              "flat": "12",
              "addressType": "WEEKDAY",
              "addressStatus": "ACTIVE"
            },
            {
              "id": "6394a8ef22ffce77649b1645",
              "city": "AAA",
              "street": "Yellow st.",
              "home": "43",
              "flat": "12",
              "addressType": "WEEKDAY",
              "addressStatus": "ACTIVE"
            },
            {
              "id": "6395b39222ffce77649b17de",
              "city": "Kielce",
              "street": "Sosnowska",
              "home": "12",
              "flat": "17",
              "addressType": "WEEKDAY",
              "addressStatus": "ACTIVE"
            },
            {
              "id": "6395b59422ffce77649b180a",
              "city": "Toruń",
              "street": "Oroniowa",
              "home": "2",
              "flat": "17",
              "addressType": "WEEKDAY",
              "addressStatus": "ACTIVE"
            },
            {
              "id": "6395b65622ffce77649b1839",
              "city": "Radom",
              "street": "Lipowa",
              "home": "276",
              "flat": "1A",
              "addressType": "WEEKEND",
              "addressStatus": "ACTIVE"
            },
            {
              "id": "6395c98f22ffce77649b1877",
              "city": "Sosnowiec",
              "street": "Zbożowa",
              "home": "87",
              "flat": "9",
              "addressType": "WEEKEND",
              "addressStatus": "ACTIVE"
            }
          ]
        }
      }
    },

JQ Task:

 {
      "name": "jq_transform",
      "taskReferenceName": "customer_transformed",
      "inputParameters": {
        "data": "${customer.output.response.body.data}",
        "queryExpression": ".data.customer|{id,name,surname,\"weekAddress\":[.addresses[]|select(.addressType==\"WEEKDAY\")][0],\"weekendAddress\":[.addresses[]|select(.addressType==\"WEEKEND\")][0]}"
      },
      "type": "JSON_JQ_TRANSFORM",
      "startDelay": 0,
      "optional": false,
      "asyncComplete": false
    }

Output:

{
  "data": {
    "weekendAddress": {
      "id": "6395b65622ffce77649b1839",
      "city": "Radom",
      "street": "Lipowa",
      "home": "276",
      "flat": "1A",
      "addressType": "WEEKEND",
      "addressStatus": "ACTIVE"
    },
    "surname": "Jons",
    "weekAddress": {
      "id": "6394a00022ffce77649b15ee",
      "city": "London",
      "street": "Yellow st.",
      "home": "43",
      "flat": "12",
      "addressType": "WEEKDAY",
      "addressStatus": "ACTIVE"
    },
    "name": "Jack",
    "id": "6390dda34b1a9e9449a05c3e"
  }
}

Json fields order in the result: weekendAddress, surname, weekAddress, name, id Expected result (according to the JQ filter): id, name, surname, weekendAddress, weekAddress

So, why the JSON_JQ_TRANSFORM task is returning the json's fields in incorrect order? How to fix that?

grmi-developer avatar Dec 11 '22 13:12 grmi-developer