Filtering the highest value key from an object

Set up a change node to use this JSONata expression (the J: option):

payload.expressions.$spread()^(>*)[0]

I know, so readable, right? wth?!?

In human terms, it "spreads" the object fields into an array of single-field objects, then sorts them descending by value, and returns only the first one. If you have not looked at JSONata, it uses a very powerful lambda expression syntax to restructure JSON objects/arrays (similar to using XPath for XML data). It takes an hour or so to wrap your head around, but well worth knowing how to use in node-red, imo.

2 Likes