How to Sort an Array Based on Key/Column name

Hi ,

I have an array which i want to sort it by the keys/column.
{
array1:[
{
" Width":“4”
" Length":“5 "
" Item Desc”:"Black ",
" Item ":"Pen "

  },

{
   "Width":"5"
  " Length":"7 "
   " Item Desc":"Blue ",
   " Item ":"Pen " ,
 }
]

}
Output:-
{
array1:[
{
" Item ":“Pen " ,
" Item Desc”:"Black “,
" Length”:“5 "
" Width”:“4”
},

{
   " Item Desc":"Blue ",
   " Item ":"Pen " 
    " Length":"7 "
    "Width":"5"
  }

Hi,
You can use the expression that’s in the mapper in the attached pipelinesort_2021_02_03.slp (3.5 KB) to sort the the elements.

Here’s a simpler expression that will work with any number of keys without modification:

$array1.map(e => e.entries().sort().toObject(x => x[0], x => x[1]))