title: JSONata sort / order by of an array
body: <p>I want to order an array. The JSONata expression below has an incoming array as follows.</p>
  
  <pre><code>[{"id":"Air-1a",
    "Controller":"ESP62",
   "Cntr-TaskNo":10,
   "Cntr-GPIO":13,
   "name":"Air",
   "valueName":"Humidity",
   "Sensor":"DHT22",
   (and many other key pairs)}, 
   {next object}, ...]
  </code></pre>
  
  <p>I then transform the array with the following JSONata expression:</p>
  
  <pre><code>payload.(
          { "Controller" : $.Controller,
            "Cntr-TaskNo": $.CntrDef.TaskNo,
            "Cntr-GPIO"  : $.CntrDef.GPIO,
            "name"       : $.name,
            "valueName"  : $.valueName,
            "Sensor"     : $.Sensor,
            "id"         : $.id
          }
  ) 
  </code></pre>
  
  <p>But now I want to - in the same JSONata expression, sort on firstly the Controller, and then the GPIO. To tried with the Controller only first.</p>
  
  <p>I tried:</p>
  
  <pre><code>payload.(
          { $sort("Controller",function($l, $r){$l.Controller &gt; $r.Controller}) : $.Controller ,
            "Cntr-TaskNo": $.CntrDef.TaskNo,
            "Cntr-GPIO"  : $.CntrDef.GPIO,
            "name"       : $.name,
            "valueName"  : $.valueName,
            "Sensor"     : $.Sensor,
            "id"         : $.id
          }
  ) 
  </code></pre>
  
  <p>As well as trying to add the sort function at the end with the ~> chaining command. I also tried the <a href="https://docs.jsonata.org/control-operators#order-by" rel="nofollow noreferrer">order-by</a> operator. </p>
  
  <p>Could anyone point me in the right direction?</p>
  
  <p>//---------- 
  The new flow with the changed 'ESP62' to '-' that does not work:   </p>
  
  <pre><code>[{"id":"874b0c77.f87418","type":"inject","z":"6f27a311.d135bc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":180,"wires":[["8c196590.c20638"]]},{"id":"8c196590.c20638","type":"change","z":"6f27a311.d135bc","name":"Dataset","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"id\":\"Air-1a\",\"Controller\":\"ESP62\",\"CntrTaskNo\":10,\"CntrGPIO\":13,\"name\":\"Air\",\"valueName\":\"Humidity\",\"Sensor\":\"DHT22\",\"aaa\":\"111\",\"bbb\":\"222\",\"ccc\":\"333\"},{\"id\":\"Air-2a\",\"Controller\":\"ESP72\",\"CntrTaskNo\":11,\"CntrGPIO\":14,\"name\":\"Air\",\"valueName\":\"Humidity\",\"Sensor\":\"DHT22\",\"aaa\":\"444\",\"bbb\":\"555\",\"ccc\":\"666\"},{\"id\":\"Air-1a\",\"Controller\":\"ESP62\",\"CntrTaskNo\":2,\"CntrGPIO\":9,\"name\":\"Air\",\"valueName\":\"Humidity\",\"Sensor\":\"DHT22\",\"aaa\":\"777\",\"bbb\":\"888\",\"ccc\":\"999\"},{\"id\":\"Air-1a\",\"Controller\":\"-\",\"CntrTaskNo\":10,\"CntrGPIO\":12,\"name\":\"Air\",\"valueName\":\"Humidity\",\"Sensor\":\"DHT22\",\"aaa\":\"777\",\"bbb\":\"888\",\"ccc\":\"999\"}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":180,"wires":[["13981162.14e28f"]]},{"id":"c8a256a5.a170c8","type":"debug","z":"6f27a311.d135bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":180,"wires":[]},{"id":"13981162.14e28f","type":"change","z":"6f27a311.d135bc","name":"Jsonata $sort","rules":[{"t":"set","p":"payload","pt":"msg","to":"($sort(payload,function($l , $r){$l.Controller &gt; $r.Controller}) ; \t$sort(payload,function($l , $r){$l.CntrGPIO &gt; $r.CntrGPIO}))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":180,"wires":[["c8a256a5.a170c8"]]}]
  </code></pre>