Not able to read a value from JSON object

Hi,

I am struggling since hours with a really basic job: Catching a simple value out of a JSON object. Not a big deal. I don't know what I am doing wrong...

JSON object passes in by websocket in node (BTW: first time I am using this injection method).

Source is:

{
   "00000000-0000-0000-0000-000000000000":{
      "datapoints":{
         "ABB7F599D3C0/ch0000/idp0009":"17",
         "ABB702630C61/ch0000/odp0001":"17"
      },
      "devices":{
         
      },
      "devicesAdded":[
         
      ],
      "devicesRemoved":[
         
      ],
      "scenesTriggered":{
         
      }
   }
}

Debug node shows the following:

29.8.2022, 21:40:10node: e7771e114dcbd3d0
msg : Object
object
00000000-0000-0000-0000-000000000000: object
datapoints: object
ABB7F599D3C0/ch0000/idp0009: "17"
ABB702630C61/ch0000/odp0001: "17"
devices: object
empty
devicesAdded: array[0]
devicesRemoved: array[0]
scenesTriggered: object
empty
_session: object
type: "websocket"
id: "4942fe41c9a87306"
_msgid: "5b6849dcbb2015c4"

->> I tried several methods within functions, change, JSONata, (...) to catch the value "17" (datapoints.ABB7F599D3C0/ch0000/idp0009)

Nothing works. :frowning:
Any suggestions what might be wrong? TIA!

Welcome to the forum @b0denl0s

It isn't a JSON object, it is a javascript object. JSON is always a string.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

If you still can't get it going in a Change node or Function node then show us what you have tried.
I suggest staying clear of JSONata until you have mastered other techniques.

You could use JSONata to pull ABB7F599D3C0/ch0000/idp0009 property value with wildcard recursive $$.**.'ABB7F599D3C0/ch0000/idp0009'

Thanks E1cid - that works!

But have you learnt anything, so that next time you have a similar problem you will be able to do it without asking for help?

Not completely... But I am just workin on it... Still reading the docs you have linked...

Yes for these i normally use a switch node and switch on the property of the object and then send that out to different paths for different objects (you get this sort of structure with Tasmota on ESP devices with multiple DS18B20 temp sensors)

I find it much easier to come back in a years time and look at the switch node than try to understand what the Jsonata is doing - i have been struggling for a year or so and still do not use it regularly enough to master it

Craig

2 Likes

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