ndarkness ndarkness - 1 year ago 81
Node.js Question

How many nested options can node-red handle?

I was wondering if there is a maximum addressing depth for json formatted files in node-red.

For instance, I have a message like this

{ topic: 'i/devices/i/up',
{ payload: 'oo',
port: 2,
counter: 54,
[ { frequency: 868.3,
datarate: 'SF12BW125',
codingrate: '4/5',
gateway_timestamp: 4201744244,
channel: 1,
server_time: '2016-07-01T09:50:39.725658999Z',
rssi: -63,
lsnr: 8.2,
rfchain: 1,
crc: 1,
modulation: 'LORA',
gateway_eui: 'oo',
altitude: 0,
longitude: 0,
latitude: 0 } ] },
qos: 2,
retain: false,
_msgid: '81960b41.7e69f8',
metadata: <Buffer 00> }

if I wan to get metadata option, I was addressing it within a function in node red like

msg.payload.rssi = msg.payload.metadata["rssi"];
return msg;

However, when I attach a debug function to it, I don't get the rssi value that I want, what am I doing wrong? Cannot that field be addressed like that?

Thanks in advance


Answer Source

There is no limit to the depth of a JSON object you access.

You've missed out an array index out of the selector.

What you need is:

msg.payload.rssi = msg.payload.metadata[0].rssi;
return msg;

This is because the metadata object is an array so could hold multiple instances of the metadata objects.

Also be aware that the debug tab in the Node-RED editor will truncate longer objects, if you need to see the whole object it is easiest to check the "output to console" box and the whole message will be printed to the console as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download