JSONata examples flows.node-red.org not working

There are inbuilt RED.util for
prepareJSONataExpression
and
evaluateJSONataExpression

example

[{"id":"97198c59935dad84","type":"function","z":"d1395164b4eec73e","name":"$length(str)","func":"// $length(string)\n\nconst example = [];\nexample[0] = \"hello world\";\nexample[1] = [\"test array\"];\nexample[2] = false;\nexample[3] = null;\n\n// Returns the number of characters in the string\nmsg.payload = [];\nexample.forEach((element, index) => {\n    let expression = RED.util.prepareJSONataExpression(`$length(\"${example[index]}\")`,node.id);\n    RED.util.evaluateJSONataExpression(expression, example, function(err, count) {\n        if (err) {\n            node.warn(JSON.stringify(err));\n        }\n            msg.payload[index] = count;\n        \n    })\n})\n\n\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":7580,"wires":[["139d3d075aef541b"]]},{"id":"c4e236b5f403ca46","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":390,"y":7580,"wires":[["97198c59935dad84"]]},{"id":"139d3d075aef541b","type":"debug","z":"d1395164b4eec73e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":7560,"wires":[]}]
1 Like