2022.1

Table Of Contents
Parsing a JSON string
When a JSON file is read, the result is a JSON string. In order to access its data, that string
needs to be parsed to its JavaScript Object representation. Node-RED provides the JSON
node to do this conversion.
The parsed data is written to the payload property of the msg object, which is passed on to the
next node. Keys in the JSON become properties of the payload.
Example
After reading the manifest.json file using a read file node, a startup flow must parse the JSON
string in order to add the keys and values to msg.payload. The manifest.json file has the
following content:
{
"email": "Laura from OL Acme <laura@ol-acme.com>",
"someApi": "http://localhost/myendpoint",
"workspace": "C:\\workspace",
"resources": [
"olsg-invoice.OL-template",
"olsg-invoice-XML.OL-datamapper"
]
}
1. Add a JSON node after the read file node. Make sure the JSON node is connected to the
output port of the read file node.
2. Add a debug node and connect the JSON node to the input port of that debug node so
that the result can be viewed in the debug message console, once the flow is deployed.
After the JSON file is parsed, the msg object will have the following properties:
msg.payload.email, msg.payload.someApi, msg.payload.workspace and
msg.payload.resources.
Using variables
There are various ways to set and get the values of (global and other) variables, for example:
l Via the change node. A 'Set' rule can set the value of one variable to a hard-coded value
or to the value of another variable (e.g. 'Set' global.email to msg.email object).
Page 206