Good afternoon
If is not a bit f abuse can someone help me to access prinTime (as example) on message below in order to get it as mesg.payload?
{"_timestamp": 1557336569, "progress": 43, "printer_data": {"progress": {"completion": 43.0026015784234, "printTimeLeftOrigin": "genius", "printTime": 6544, "printTimeLeft": 8911, "filepos": 5236192}, "state": {"text": "Printing", "flags": {"cancelling": false, "paused": false, "operational": true, "pausing": false, "printing": true, "resuming": false, "sdReady": false, "error": false, "ready": false, "finishing": false, "closedOrError": false}}, "currentZ": 4.1, "job": {"averagePrintTime": 15455.695065021515, "lastPrintTime": 15455.695065021515, "user": "david", "file": {"origin": "local", "name": "Husky_logo_60--PLAx4.gcode", "date": 1557276735, "path": "Husky_logo_60--PLAx4.gcode", "display": "Husky logo 60%-PLAx4.gcode", "size": 12176454}, "estimatedPrintTime": 13151.32884912111, "filament": {"tool0": {"volume": 12.156581574058073, "length": 5054.119170014139}}}, "offsets": {}}, "location": "local", "path": "Husky_logo_60--PLAx4.gcode"}
Thanks in advance
Hi @davidcgu
This page the docs explains how to understand the structure of a message and identify the path to any element: https://nodered.org/docs/user-guide/messages
The more I try the most lost I am, is an object inside another object inside another object and this is making me a bit crazy in order to understand how to access there.
Sorry
If you pass the message to a Debug node, you can explore its structure to find the element you are interested in:
When you hover over the element you care about, you'll see a pair buttons appear on the right.
Clicking on the first button will copy the path to the item to your clipboard. In this instance it gives:
payload.printer_data.progress.printTime
Which you can then use directly in a Change node, or add msg.
to the beginning if you want to use it in a Function node.
Thanks Nick for your help,
In fact this is what make it so difficult for me to understand because on debug message shows me all in a row instead of giving me separated paths.
Regards
Hi David,
the page in the docs I linked to says this: Working with messages : Node-RED
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.
I must be an idiot..... had the json conversion for the node but was looking at the debug prior to that what was making me totally confused, now solved, thanks a lot Nick!