How Set msg.payload to a json stream buffer?

#1

i have recently installed json to csv converter. And i can't figure out how can set msg.payload to a json stream buffer for the input.

0 Likes

#2

What have you tried so far? Have you tried a google search with something like how to create a json object?

1 Like

#3

no but i have tried it and this is what i get in my file
payload.data3,payload.data1,payload.data2,socketid,_msgid,payload,templateScope 128,ss,dd,8hMoh7BG0EwLFIS9AAAB,3d362411.42d19c,, ,,,,3d362411.42d19c,, 46,e,c,8hMoh7BG0EwLFIS9AAAB,c196b0d8.569a4,,local ,,,,c196b0d8.569a4,, 5588,ee,c,8hMoh7BG0EwLFIS9AAAB,297f1077.a301c,,local ,,,,297f1077.a301c,, 3,e,eec,8hMoh7BG0EwLFIS9AAAB,fa6b908a.ca50f,,local ,,,,fa6b908a.ca50f,,

0 Likes

#4

If you are converting a Javascript object to a json object and then to csv. You can do that in one step with the CSV node. Which will go direct from a javascript object direct to CSV.

Your flow appears to lack any debug nodes along the flow. If you get an output that isn't what you expect, the easiest thing to do is to add debug nodes along your flow and see where you get a result that you weren't expecting.

Also when we ask what have you tried? Show us your flow? The most helpful is to export your flow from node-RED and post it here (after reading the link that I posted in the other thread)

But given the image you added here, you now appear to have three different threads relating to the same problem, please don't add any more! If you have discovered something else as you investigate the issue, you can add to a post.

0 Likes

#5

ok here's my flow
[{"id":"d698f710.39d498","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"7646f71d.0c6548","type":"ui_template","z":"d698f710.39d498","group":"1dc1526e.1e610e","name":"","order":0,"width":0,"height":0,"format":"<style>\n /* The Modal (background) */\n body {font-family: Arial, Helvetica, sans-serif;}\n\n /* The Modal (background) */\n .modal {\n display: none; /* Hidden by default */\n position: fixed; /* Stay in place */\n z-index: 1; /* Sit on top */\n padding-top: 100px; /* Location of the box */\n left: 0;\n top: 0;\n width: 100%; /* Full width */\n height: 100%; /* Full height */\n overflow: auto; /* Enable scroll if needed */\n background-color: rgb(0,0,0); /* Fallback color */\n background-color: rgba(0,0,0,0.4); /* Black w/ opacity */\n }\n\n /* Modal Content */\n .modal-content {\n position: relative;\n background-color: #e6e6e6;\n margin: auto;\n padding: 0;\n border: 1px solid #888;\n width: 50%;\n box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);\n -webkit-animation-name: animatetop;\n -webkit-animation-duration: 0.4s;\n animation-name: animatetop;\n animation-duration: 0.4s\n }\n\n /* Add Animation */\n @-webkit-keyframes animatetop {\n from {top:-300px; opacity:0}\n to {top:0; opacity:1}\n }\n\n @keyframes animatetop {\n from {top:-300px; opacity:0}\n to {top:0; opacity:1}\n }\n\n /* The Close Button */\n .close,.close_f {\n color: #004d66;\n float: right;\n font-size: 28px;\n font-weight: bold;\n }\n\n .close:hover,\n .close_f:hover,\n .close:focus,\n .close_f:focus {\n color: #000;\n text-decoration: none;\n cursor: pointer;\n }\n\n .modal-header {\n padding: 20px 16px;\n background-color: #004d66;\n }\n\n .modal-body {padding: 2px 16px;}\n\n .modal-footer {\n padding: 20px 16px;\n background-color: #004d66;\n }\n#outer\n{\n width:100%;\n text-align: center;\n}\n.inner\n{\n display: inline-block;\n}\n#myBtn1,#myBtn2,#myBtn3,#myBtn4,#myBtn5 {\n background-color: #004d66;\n border: none;\n color: white;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 16px;\n margin: 4px 2px;\n cursor: pointer;\n i {\n padding-right: 0.3em;\n }\n}\n\n</style>\n\n<!-- Trigger/Open The Modal -->\n\n<div id=\"outer\">\n <div class=\"inner\"><button class=\"inner\" id=\"myBtn1\">Button1</button></div>\n <div class=\"inner\"><button class=\"inner\" id=\"myBtn2\">Button2</button></div>\n <div class=\"inner\"><button class=\"inner\" id=\"myBtn3\">Button3</button></div>\n <div class=\"inner\"><button class=\"inner\" id=\"myBtn4\">Button4</button></div>\n <div class=\"inner\"><button class=\"inner\" id=\"myBtn5\">Button5</button></div>\n</div>\n<script type=\"text/javascript\">\nvar msg ={};\n\n</script>\n<!-- The Modal -->\n<div id=\"myModal\" class=\"modal\" >\n\n <!-- Modal content -->\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <span class=\"close\">&times;</span>\n <h2>Saisie votre matricule</h2>\n </div>\n <div class=\"modal-body\">\n <h3>Matricule : </h3> <br>\n <input type=\"number\" ng-model=\"msg.payload.data3\" id=\"matricule\" name=\"matricule\" size=\"100\" min=\"0\"><br><br>\n <button id=\"myBtn_m\">Entrer</button>\n </div>\n <div class=\"modal-footer\">\n</div>\n </div>\n\n</div>\n\n\n<div id=\"myModal_f\" class=\"modal\">\n\n <!-- Modal content -->\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <span class=\"close_f\">&times;</span>\n <h2>Formulaire</h2><br>\n </div>\n\n <div class=\"modal-body\">\n <h3>Nom :</h3><input type=\"text\" ng-model=\"msg.payload.data1\" id=\"name\" name=\"Nom\" placeholder=\"Nom\" size=\"77\"><br><br>\n <h3>Prenom : </h3><input type=\"text\" ng-model=\"msg.payload.data2\" id=\"prenom\" name=\"Prenom\" placeholder=\"Prenom\" size=\"77\"> <br><br>\n <button id=\"myBtn_f\" ng-click=\"send(msg)\" ng-disabled=\"(msg.payload.data1 == null) || (msg.payload.data2 == null)\">Enregistrer</button>\n</div>\n<div class=\"modal-footer\">\n</div>\n </div>\n\n</div>\n\n<script>\n\n // Get the modal\n\nvar modal = document.getElementById('myModal');\nvar modal_f = document.getElementById('myModal_f');\n\n// Get the button that opens the modal\nvar btn = document.getElementById(\"myBtn1\");\nvar btn_m = document.getElementById(\"myBtn_m\");\nvar btn_f = document.getElementById(\"myBtn_f\");\n\n// Get the <span> element that closes the modal\nvar span = document.getElementsByClassName(\"close\")[0];\nvar span_f = document.getElementsByClassName(\"close_f\")[0];\n\n// When the user clicks on the button, open the modal\nbtn.onclick = function() {\n modal.style.display = \"block\";\n}\nbtn_m.onclick = function() {\n var x = document.getElementById(\"matricule\").value;\n if(x == 0 )\n { alert(\"Entrer votre matricule\");\n return false;\n }\n else{\n modal.style.display = \"none\";\n modal_f.style.display = \"block\";\n }\n\n}\nbtn_f.onclick = function() {\n modal_f.style.display = \"none\";\n}\n\n// When the user clicks on <span> (x), close the modal\nspan.onclick = function() {\n modal.style.display = \"none\";\n}\nspan_f.onclick = function() {\n modal_f.style.display = \"none\";\n}\n\n// When the user clicks anywhere outside of the modal, close it\nwindow.onclick = function(event) {\n if ((event.target == modal)||(event.target == modal_f)) {\n modal.style.display = \"none\";\n modal_f.style.display = \"none\";\n\n }\n}\n</script>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":160,"y":140,"wires":[["611ef4e5.a2263c","727d4f61.19de3"]]},{"id":"611ef4e5.a2263c","type":"function","z":"d698f710.39d498","name":"test","func":"function formatDate(date) {\n var d = new Date(date),\n month = '' + (d.getMonth() + 1),\n day = '' + d.getDate(),\n year = d.getFullYear();\n\n if (month.length < 2) month = '0' + month;\n if (day.length < 2) day = '0' + day;\n\n return [year, month, day].join('_');\n}\nvar tempString =formatDate(Date().toString());\n//var tempString1 =\"//192.168.1.14/partage/\";\n//var tempString1 =\"//A3EMECA/Users/Public/Partage/\";\nvar tempString1 = \"C:\\\\Users\\\\hathemi\\\\.node-red\\\\files\\\\\";\nvar tempString2 = tempString1.concat(tempString);\nvar finalPath = tempString2.concat(\"_export.csv\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":140,"wires":[["20221be.624c1e4"]]},{"id":"57b74324.e7fc7c","type":"file","z":"d698f710.39d498","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","x":610,"y":140,"wires":[["bced108b.35d2c"]]},{"id":"bced108b.35d2c","type":"function","z":"d698f710.39d498","name":"","func":"msg={};\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":200,"wires":[["7646f71d.0c6548"]]},{"id":"20221be.624c1e4","type":"csv","z":"d698f710.39d498","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\r\\n","temp":"","skip":"0","x":450,"y":140,"wires":[["57b74324.e7fc7c"]]},{"id":"7d9f6575.57f99c","type":"HTML-PDF","z":"d698f710.39d498","name":"HTML-PDF","output":"file","x":730,"y":360,"wires":[["46c20465.c92edc"]]},{"id":"46c20465.c92edc","type":"file","z":"d698f710.39d498","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","x":730,"y":300,"wires":[[]]},{"id":"727d4f61.19de3","type":"function","z":"d698f710.39d498","name":"","func":"// Créé une variable pour stocker le journal du dashboard si inexistante\n// initialise the counter to 0 if it doesn't exist already\nvar dashboardLog = context.get('dashboardLog')|| [];\n\ndashboardLog.push(msg);\n\n// Enregistre les messages du dashboard pour le prochain affichage\n// store the value back\ncontext.set('dashboardLog',dashboardLog);\n// Affiche le journal des messages\n// make it part of the outgoing msg object\nmsg = {};\nmsg.payload = dashboardLog;\nreturn msg;\n","outputs":1,"noerr":0,"x":150,"y":280,"wires":[["5900cd9e.5b20c4"]]},{"id":"5900cd9e.5b20c4","type":"function","z":"d698f710.39d498","name":"test","func":"function formatDate(date) {\n var d = new Date(date),\n month = '' + (d.getMonth() + 1),\n day = '' + d.getDate(),\n year = d.getFullYear();\n\n if (month.length < 2) month = '0' + month;\n if (day.length < 2) day = '0' + day;\n\n return [year, month, day].join('_');\n}\n\nvar tempString =formatDate(Date().toString());\n//var tempString1 =\"//192.168.1.14/partage/\";\n//var tempString1 =\"//A3EMECA/Users/Public/Partage/\";\nvar tempString1 = \"C:\\\\Users\\\\hathemi\\\\.node-red\\\\files\\\\\";\nvar tempString2 = tempString1.concat(tempString);\nvar finalPath = tempString2.concat(\"_export.pdf\");\nmsg.filename=finalPath;\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":400,"wires":[["6d738840.8ea2e8"]]},{"id":"a8ed6b6a.d535b8","type":"json-2-csv","z":"d698f710.39d498","name":"","x":500,"y":360,"wires":[["7d9f6575.57f99c","9875538d.03df2"]]},{"id":"6d738840.8ea2e8","type":"json","z":"d698f710.39d498","name":"","property":"payload","action":"obj","pretty":false,"x":310,"y":360,"wires":[["a8ed6b6a.d535b8"]]},{"id":"9875538d.03df2","type":"debug","z":"d698f710.39d498","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":700,"y":440,"wires":[]},{"id":"1dc1526e.1e610e","type":"ui_group","z":"","name":"","tab":"d683d6f0.5632b8","order":4,"disp":true,"width":"26","collapse":false},{"id":"d683d6f0.5632b8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

0 Likes

#6

Great you have correctly shared your flows BUT...

You have some nodes that are not part of the core. What are they (and tell the full name i.e. node-red-contrib-blahblah) that will save time for the people who are willing to give you some of their time to help you solve your issue.

And it's reallly a good idea, if you want help, to figure out where your problem is and isolate that section of your flow and create some test data - maybe via a inject node - that will show the problem.

Make it easy for people to help you or thy may decide to pass on your problem and go help someone else.

0 Likes