Sort internal array

hi there,

I have a inbound json thats coming this way.

How can I sort the Order-Lines array based on line-num in asscending order. tried to use sort but did not work.

any other solutions?

Thanks
Manohar

[
  {
    "order-lines": [
      {
        "line-num": "00010",
        "attachments": {
          "type": "AttachmentText",
          "intent": "Supplier",
          "text": "2021-09-02 17:35 :-  Blade #60272"
        },
        "need-by-date": "20210901"
      },
      {
        "line-num": "00030",
        "attachments": {
          "type": "AttachmentText",
          "intent": "Supplier",
          "text": "2021-09-02 17:35 :-  Blade # 30050"
        },
        "need-by-date": "20210901"
      },
      {
        "line-num": "00020",
        "need-by-date": "20210901"
      },
      {
        "line-num": "00040",
        "need-by-date": "20210901"
      },
      {
        "line-num": "00050",
        "need-by-date": "20210901"
      }
    ],
    "currency": {
      "code": "USD"
    },
    "custom-fields": {
      "buyer-type-req": "",
      "required-signature": {
        "external-ref-code": "3"
      }
    },
    "payment-term": {
      "code": "ZN45"
    },
    "po-number": "iuiuii989"
  }
]

Hi @manohar,

Use the following expression in a mapper:

$['order-lines'].sort((a,b) => a['line-num'] - b['line-num'])

Regards,
Bojan

1 Like