I am trying to count the number of each node type in flows.json. Not difficult using a function but I would like to do it without writing javascript code.
So read the file and split the resulting array gives me one message per node with the node type in msg.payload.type
How can I use a change node to increment a flow counter eg flow.messagecounts["function"] += 1 ?
I have tried this but I think because flow.messagecounts[msg.payload.type] is initially undefined, the increment never works?
[{"id":"e14a6f161d1bebd0","type":"inject","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":600,"wires":[["ac2c02ad65697585"]]},{"id":"c932017ee7d0618e","type":"file in","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"flows.json","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":500,"y":600,"wires":[["d9dd00679dbd79dc"]]},{"id":"d9dd00679dbd79dc","type":"json","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"","property":"payload","action":"","pretty":false,"x":630,"y":600,"wires":[["232a1f4fb159234b"]]},{"id":"232a1f4fb159234b","type":"split","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":750,"y":600,"wires":[["18620a135bbb3d51"]]},{"id":"ac2c02ad65697585","type":"change","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"delete flow.messagecounts","rules":[{"t":"delete","p":"messagecounts","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":600,"wires":[["c932017ee7d0618e"]]},{"id":"18620a135bbb3d51","type":"change","z":"db04fd79f3a93d19","g":"8b1229d76a3c7516","name":"","rules":[{"t":"set","p":"increment","pt":"msg","to":"messagecounts[msg.payload.type]","tot":"flow"},{"t":"set","p":"increment","pt":"msg","to":"increment + 1","tot":"jsonata"},{"t":"set","p":"messagecounts[msg.payload.type]","pt":"flow","to":"increment","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":660,"wires":[[]]}]