# How to use sort node using specific keys

In this tutorial we have employee record which is to type JSON array having role number, name, address, and age. We need sort this record based on the age in descending order before sending to an external system.

  1. TBD

    Following is the payload to be used for testing.

     [
         {
         "empno": 1,
         "name": "Alex",
         "age": 32
         },
         {
         "empno": 3,
         "name": "Franco",
         "age": 47
         },
         {
         "empno": 2,
         "name": "Dan",
         "age": "28"
         },
         {
         "empno": 4,
         "name": "Tony",
         "age": 30
         },
         {
         "empno": 5,
         "name": "Felix",
         "age": 40
         }
     ]
    
  2. Drag and drop the sort node to the canvas.

  3. Double click the sort node to open the editor and set the sort content as msg.payload . Also set the sort key as age . Click Save.

  4. Wire the sort node with TBD.

  5. Drop an debug node to the canvas and name it as Completed.

  6. Wire the sort node to debug node.

  7. Click on the TBD to trigger the test .

Observation

The provided employee record payload should be showing (on the debug panel on the editor) in descending order.

[
    {
    "empno":3,
    "name":"Franco",
    "age":47
    },
    {
    "empno":5,
    "name":"Felix",
    "age":40
    },
    {
    "empno":1,
    "name":"Alex",
    "age":32
    },
    {
    "empno":4,
    "name":"Tony",
    "age":30
    },
    {
    "empno":2,
    "name":"Dan",
    "age":"28"
    }
]