# Sorting Values - JSON

**URL:** <https://discourse.nodered.org/t/sorting-values-json/51299>\
**Category:** General\
**Created:** [20 September 2021 16:37 UTC](https://discourse.nodered.org/t/sorting-values-json/51299 "2021-09-20T16:37:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshwilliams](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joshwilliams](https://discourse.nodered.org/u/joshwilliams)\
**Post date:** [20 September 2021 16:37 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/1 "2021-09-20T16:37:42Z")

</div>

Hi Everyone,

I'm really new to all of this!

I currently have a UDP stream of scoreboard data and I can parse it with CSV and JSON and then output it to a file that my graphics system can look at.

What I'm trying to do now, is sort that data based on a particular column's data. Done some Googling and tried a few things on here to no avail.

Any help would be greatly appreciated!

Many thanks

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 September 2021 17:08 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/2 "2021-09-20T17:08:57Z")

</div>

You can use the change node to sort the object using JSONata expression :J `$$.payload^(name)`  
that would sort `msg.payload` by the property `name`. Adding \< or \> before name would set ascending or descending, to order by more properties just and property names separated by a comma

> **[Path Operators · JSONata](https://docs.jsonata.org/path-operators#---order-by)**
>
> The path operators underpin the declarative nature of the map/filter/reduce processing model in JSONata.

I would help more but you offer no data to give you a working example.

---

<div class="post-metadata">

**Author:** ![joshwilliams](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joshwilliams](https://discourse.nodered.org/u/joshwilliams)\
**Post date:** [21 September 2021 18:42 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/3 "2021-09-21T18:42:59Z")

</div>

Hi, thanks for getting back to me.

This is how the data currently comes out:

msg.payload : array[9]  
array[9]  
0: object  
col1: "1"  
col2: "Emily Cocksedge"  
col3: "Hertford"  
col4: " 16.75"  
col5: "2"  
col6: " 1"  
col7: null  
1: object  
col1: "2"  
col2: "Xenia Coole"  
col3: "Essex"  
col4: " 17.14"  
col5: "4"  
col6: " 1"  
col7: null

etc.

I'd like to sort by "col5"

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 September 2021 18:45 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/4 "2021-09-21T18:45:55Z")

</div>

That would be  
`$$.payload^(col5)`

---

<div class="post-metadata">

**Author:** ![joshwilliams](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joshwilliams](https://discourse.nodered.org/u/joshwilliams)\
**Post date:** [21 September 2021 18:47 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/5 "2021-09-21T18:47:08Z")

</div>

Perfect! Exactly what I needed. Thank you!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 September 2021 18:48 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/6 "2021-09-21T18:48:27Z")

</div>

When you copy data to the forum it is necessary for the data to be presented in a usable format and correctly formatted using the `</>` button.

Look at the copy value button that appears under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 November 2021 18:49 UTC](https://discourse.nodered.org/t/sorting-values-json/51299/7 "2021-11-20T18:49:01Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
