Problems accessing an object

I am trying to get the data contained in the events in this object:

If I copy the path of the first object (0: object) it gives me:[0]

But when I run the function:

msg.payload = => {
    return {
        start: event.start,
        end: event.end,
        note: event.note

return msg;

I get "TypeError: Cannot read properties of undefined (reading 'info')"
The path looks correct to me. What am I doing wrong?

Use the "copy path" tools node-red provides to ensure correct path.

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.


Additionally, use node.warn in your function e.g. node.warn({"msg.area": msg.area}) just before you access it.

Lastly, this is easier with the split and join nodes :slight_smile:

Thanks but I copied the path “ If I copy the path of the first object (0: object) it gives me:[0]”

That confirms that message contained and it was an array THIS TIME, but as you did see the below error at some point _

_ it suggests a previous msg came through WITHOUT .area resulting in a type error (that is literally what the error says - couldnt read info from undefined i.e. msg.area was undefined & why I said to add node.warn({"msg.area": msg.area}) just before you access it.

If you think there are places a msg could come through that sometimes does NOT have the area property, and that is OK, then you will need to guard against it.

e.g... add a switch node before the function that checks msg.area is type of object OR in your function:

if (!Array.isArray(msg.area?.info?.events)) {
   node.error(" is NOT an array!", msg) // throw catchable error
   return null // halt the flow
// original code below
// ...
// ...
return msg

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