Filtering the highest value key from an object


I am trying to filter out the key with the highest number from this object.
I have tried to do it with a split node, but it does not give the key, just the number.
Been searching the forum but nothing I found works.
Does anyone know how to do this with a quick function node so that the output will show the "key AND number" of the highest value only?

In this case the output of msg.payload would be (neutral : 0.976....)


Thanks in advance.

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


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.


Thanks for the quick response and detailed expanation @shrickus
That was just what I wanted, easy when you know how...

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