In nodered I want to add a JSON object to an array stored in a global context object.
The global context is initialized as
{
"lot":
{
"total":0,
"free":0,
"occupied":0,
"cams":[]
}
}
When an HTTP request happens I need to add an object to the global context cams
.
I try to do this using a change
node with Set
context.lot.cams
to the following JSONATA:
$append(global.context.lot.cams,
{$string(msg.req.params.cam) :
{"total" : msg.req.body.totalLots,
"free" : msg.req.body.totalLots - msg.req.body.occupied,
"occupied" : msg.req.body.occupied}
}
)
However instead of appending it overwrites the cams
array with the new element.
How to append a custom object built using http request parameters to a global context array in node-red?