cancel
Showing results for 
Search instead for 
Did you mean: 

Sort internal array

manohar
Contributor

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"
  }
]
1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

Hi @manohar,

Use the following expression in a mapper:

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

Regards,
Bojan

View solution in original post

1 REPLY 1

bojanvelevski
Valued Contributor

Hi @manohar,

Use the following expression in a mapper:

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

Regards,
Bojan