You are on page 1of 2

Understanding the structure of a message

The easiest way to understand the structure of a message is to pass it to a Debug


node and view it in the Debug sidebar.

By default, the Debug node will display the msg.payload property, but can be
configured to display any property or the whole message.

When displaying an Array or Object, the sidebar provides a structured view that can
be used to explore the message.

 At the top it shows the name of the property that has been passed in. Here, the
default msg.payload has been used.
 Next to the property name is the type of the property - Object, String, Array etc.
 It then shows the contents of the property. For Arrays and Objects, the property is
collapsed into a single line. By clicking on it, the property will expand to show more
detail.

When you hover over any element, a set of buttons appear on the right:

 : copies the path to the selected element to your clipboard. In this example, it
will copy payload.Phone[2].type. This allows you to quickly determine how to
access a property in a Change or Function node.
 : copies the value of the element to your clipboard as a JSON string. Note
that the sidebar truncates Arrays and Buffers over a certain length. Copying
the value of such a property will copy the truncated version.
 : pins the selected element so it is always displayed. When another message
is received from the same Debug node, it is automatically expanded to show
all pinned elements.

Working with JSON

JSON, (JavaScript Object Notation), is a standard way for representing a JavaScript


object as a String. It is commonly used by web APIs to return data.

If a message property contains a JSON string it must first be parsed to its equivalent
JavaScript object before the properties it contains can be accessed. To determine
whether a property contains a String or Object, the Debug node can be used.

Node-RED provides a JSON node to do this conversion.

You might also like