[{"data":1,"prerenderedAt":1444},["ShallowReactive",2],{"node-red-\u002Fnode-red\u002Fgetting-started\u002Fnode-red-messages":3},{"id":4,"title":5,"body":6,"description":1437,"extension":1438,"meta":1439,"navigation":435,"path":1440,"seo":1441,"stem":1442,"__hash__":1443},"nodeRed\u002Fnode-red\u002Fgetting-started\u002Fnode-red-messages.md","Understanding Node-RED Messages",{"type":7,"value":8,"toc":1409},"minimark",[9,17,21,24,29,32,43,46,51,62,65,131,146,150,157,160,189,192,210,214,217,224,227,274,283,287,290,294,306,309,378,387,391,394,475,496,549,552,609,613,616,619,622,654,657,660,739,743,746,750,754,761,780,783,790,846,850,853,859,886,889,892,963,969,1010,1013,1017,1026,1029,1043,1047,1053,1056,1073,1080,1084,1087,1091,1094,1099,1138,1143,1176,1182,1191,1200,1204,1215,1219,1249,1253,1278,1282,1285,1289,1306,1310,1331,1335,1338,1342,1369,1373,1402,1405],[10,11,13],"h1",{"id":12},"",[14,15],"binding",{"value":16},"meta.title",[18,19,20],"p",{},"Node-RED operates by passing messages between nodes to create dynamic IoT, automation, and data-processing workflows. Each message transports data that nodes read, modify, process, or analyze. Understanding message structure and handling is essential for building reliable flows. Poor message management can cause subtle bugs like data overwrites, infinite loops, or system crashes.",[18,22,23],{},"This guide explores Node-RED message mechanics, common pitfalls, and best practices for maintaining smooth, error-free data flow.",[25,26,28],"h2",{"id":27},"what-are-node-red-messages","What Are Node-RED Messages?",[18,30,31],{},"Messages in Node-RED are data packets that flow between nodes in your workflow. Node-RED follows an event-driven architecture where nodes act as both event emitters and listeners, with messages serving as the communication medium between them.",[18,33,34,39],{},[35,36],"img",{"alt":37,"dataZoomable":12,"src":38},"Node-RED message passing animation","\u002Fnode-red-media\u002Fgetting-started\u002Fimages\u002Fnode-red-message-passing.gif",[40,41,42],"em",{},"Node-RED message passing visualization",[18,44,45],{},"Messages carry the data that powers your workflows—sensor readings, user inputs, API responses, and more. Fundamentally, Node-RED messages are JavaScript objects, providing a flexible structure for managing and transferring data throughout your flows.",[47,48,50],"h3",{"id":49},"javascript-objects-primer","JavaScript Objects Primer",[18,52,53,54,61],{},"A ",[55,56,60],"a",{"href":57,"rel":58},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=BRSg22VacUA",[59],"nofollow","JavaScript object"," is a data structure that stores multiple values in key-value pairs. Each key (property) associates with a specific value, allowing organized access to related data.",[18,63,64],{},"Example:",[66,67,71],"pre",{"className":68,"code":69,"language":70,"meta":12,"style":12},"language-javascript shiki shiki-themes github-light github-dark","{\n  name: \"Bob\",\n  age: 24,\n  married: true\n}\n","javascript",[72,73,74,83,100,114,125],"code",{"__ignoreMap":12},[75,76,79],"span",{"class":77,"line":78},"line",1,[75,80,82],{"class":81},"sVt8B","{\n",[75,84,86,90,93,97],{"class":77,"line":85},2,[75,87,89],{"class":88},"sScJk","  name",[75,91,92],{"class":81},": ",[75,94,96],{"class":95},"sZZnC","\"Bob\"",[75,98,99],{"class":81},",\n",[75,101,103,106,108,112],{"class":77,"line":102},3,[75,104,105],{"class":88},"  age",[75,107,92],{"class":81},[75,109,111],{"class":110},"sj4cs","24",[75,113,99],{"class":81},[75,115,117,120,122],{"class":77,"line":116},4,[75,118,119],{"class":88},"  married",[75,121,92],{"class":81},[75,123,124],{"class":110},"true\n",[75,126,128],{"class":77,"line":127},5,[75,129,130],{"class":81},"}\n",[18,132,133,134,137,138,141,142,145],{},"Here, ",[72,135,136],{},"name",", ",[72,139,140],{},"age",", and ",[72,143,144],{},"married"," are object properties. Node-RED messages use this same structure to organize and transport data within flows.",[25,147,149],{"id":148},"anatomy-of-node-red-messages","Anatomy of Node-RED Messages",[18,151,152,153,156],{},"Node-RED messages are referenced as ",[72,154,155],{},"msg"," by default, and nodes are designed around this convention.",[18,158,159],{},"Key message properties include:",[161,162,163,173,181],"ul",{},[164,165,166,172],"li",{},[167,168,169],"strong",{},[72,170,171],{},"msg._msgid",": A unique identifier automatically assigned by Node-RED for tracking and debugging messages within flows.",[164,174,175,180],{},[167,176,177],{},[72,178,179],{},"msg.payload",": The primary data container. This holds the main information that nodes process—sensor readings, user input, computed results, etc.",[164,182,183,188],{},[167,184,185],{},[72,186,187],{},"msg.topic",": An optional property for categorizing or identifying messages, useful for routing or filtering based on context.",[18,190,191],{},"These are the most frequently used properties, though additional custom properties can be added as needed.",[18,193,194,195,198,199,202,203,206,207,209],{},"The ",[72,196,197],{},"_msgid"," property appears automatically, even when sending an empty object between nodes. However, ",[72,200,201],{},"payload"," and ",[72,204,205],{},"topic"," are not always present—their inclusion depends on whether nodes append them. Most Node-RED nodes, including community-contributed ones, use ",[72,208,201],{}," as the standard communication property.",[25,211,213],{"id":212},"data-types-in-node-red-messages","Data Types in Node-RED Messages",[18,215,216],{},"Understanding data types is crucial when working with Node-RED messages. Messages themselves must always be JavaScript objects, or Node-RED will throw an error.",[18,218,219,220,223],{},"One exception: you can send ",[72,221,222],{},"null"," as a message. This effectively stops message propagation, preventing data from flowing to subsequent nodes.",[18,225,226],{},"Message property values can be any JavaScript-supported data type:",[161,228,229,236,243,250,257,264,271],{},[164,230,231],{},[55,232,235],{"href":233,"rel":234},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FString",[59],"String",[164,237,238],{},[55,239,242],{"href":240,"rel":241},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FNumber",[59],"Number",[164,244,245],{},[55,246,249],{"href":247,"rel":248},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FArray",[59],"Array",[164,251,252],{},[55,253,256],{"href":254,"rel":255},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FBoolean",[59],"Boolean",[164,258,259],{},[55,260,263],{"href":261,"rel":262},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FObject",[59],"Object",[164,265,266],{},[55,267,270],{"href":268,"rel":269},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FReference\u002FGlobal_Objects\u002FArrayBuffer",[59],"Buffer",[164,272,273],{},"Other complex data types",[18,275,276,280],{},[35,277],{"alt":278,"dataZoomable":12,"src":279},"Inject node sending different data types","\u002Fnode-red-media\u002Fgetting-started\u002Fimages\u002Fnode-red-data-types.gif",[40,281,282],{},"Various data types supported by Node-RED",[25,284,286],{"id":285},"how-to-clone-messages-and-properties","How to Clone Messages and Properties",[18,288,289],{},"Cloning creates an independent copy of a message or its properties, allowing modifications without affecting the original. This is essential when sending different versions of data to multiple flow branches or when preserving original data for comparison.",[47,291,293],{"id":292},"using-the-change-node","Using the Change Node",[18,295,194,296,299,300,302,303,305],{},[167,297,298],{},"Change"," node provides a visual interface for modifying and cloning message properties. Note that you cannot clone the entire ",[72,301,155],{}," object in change node at once—properties must be copied individually. The Change node can clone properties to other ",[72,304,155],{}," properties, or to flow\u002Fglobal context.",[18,307,308],{},"Steps to clone using the Change node:",[310,311,312,318,321,337],"ol",{},[164,313,314,315,317],{},"Double-click on the ",[167,316,298],{}," node to open its configuration dialogue.",[164,319,320],{},"You will see an interface with an existing item added by default.",[164,322,323,324,137,327,137,330,141,333,336],{},"On the left side of the field, you will see options like ",[167,325,326],{},"\"Set\"",[167,328,329],{},"\"Change\"",[167,331,332],{},"\"Delete\"",[167,334,335],{},"\"Move\"",". You can use these options to perform the corresponding operations on the message.",[164,338,339,340,342,343,346,347,349,350,353,354,356,357,360,361,364,365,368,369,371,372,374,375,377],{},"To clone the property ",[72,341,179],{}," to ",[72,344,345],{},"flow.data",", select the ",[167,348,326],{}," action. In the first ",[167,351,352],{},"\"Property\""," field, enter ",[72,355,201],{},", and in the ",[167,358,359],{},"\"to the value\""," field, select ",[167,362,363],{},"flow"," and enter ",[72,366,367],{},"data",". For cloning ",[72,370,155],{}," properties to new ",[72,373,155],{}," properties, select ",[167,376,155],{}," in the second field and specify the new property name.",[18,379,380,381,386],{},"For comprehensive information on Change node capabilities, including Delete, Move, and Change actions, refer to the ",[55,382,385],{"href":383,"rel":384},"https:\u002F\u002Fnodered.org\u002Fdocs\u002Fuser-guide\u002Fnodes",[59],"Change Node documentation",".",[47,388,390],{"id":389},"using-the-function-node","Using the Function Node",[18,392,393],{},"The Function node offers programmatic control over message cloning using JavaScript:",[66,395,399],{"className":396,"code":397,"language":398,"meta":12,"style":12},"language-js shiki shiki-themes github-light github-dark","\u002F\u002F Clone the entire message\nvar newMsg = RED.util.cloneMessage(msg);\n\n\u002F\u002F Modify the clone safely (original remains unchanged)\nnewMsg.payload = \"Modified data\";\n\n\u002F\u002F Return the original message\nreturn msg;\n","js",[72,400,401,407,431,437,442,455,460,466],{"__ignoreMap":12},[75,402,403],{"class":77,"line":78},[75,404,406],{"class":405},"sJ8bj","\u002F\u002F Clone the entire message\n",[75,408,409,413,416,419,422,425,428],{"class":77,"line":85},[75,410,412],{"class":411},"szBVR","var",[75,414,415],{"class":81}," newMsg ",[75,417,418],{"class":411},"=",[75,420,421],{"class":110}," RED",[75,423,424],{"class":81},".util.",[75,426,427],{"class":88},"cloneMessage",[75,429,430],{"class":81},"(msg);\n",[75,432,433],{"class":77,"line":102},[75,434,436],{"emptyLinePlaceholder":435},true,"\n",[75,438,439],{"class":77,"line":116},[75,440,441],{"class":405},"\u002F\u002F Modify the clone safely (original remains unchanged)\n",[75,443,444,447,449,452],{"class":77,"line":127},[75,445,446],{"class":81},"newMsg.payload ",[75,448,418],{"class":411},[75,450,451],{"class":95}," \"Modified data\"",[75,453,454],{"class":81},";\n",[75,456,458],{"class":77,"line":457},6,[75,459,436],{"emptyLinePlaceholder":435},[75,461,463],{"class":77,"line":462},7,[75,464,465],{"class":405},"\u002F\u002F Return the original message\n",[75,467,469,472],{"class":77,"line":468},8,[75,470,471],{"class":411},"return",[75,473,474],{"class":81}," msg;\n",[18,476,477,480,481,484,485,488,489,492,493,495],{},[167,478,479],{},"Critical Note:"," Direct assignment like ",[72,482,483],{},"let newMsg = msg;"," does ",[167,486,487],{},"not"," create a true clone. It creates a reference to the same object, meaning changes to ",[72,490,491],{},"newMsg"," will affect ",[72,494,155],{}," as both point to the same data.",[66,497,499],{"className":396,"code":498,"language":398,"meta":12,"style":12},"\u002F\u002F This creates a reference, NOT a clone\nvar newMsg = msg;\n\n\u002F\u002F Modifying newMsg also modifies the original msg\nnewMsg.payload = \"Modified data\";\n\nreturn msg; \u002F\u002F The original is now changed!\n",[72,500,501,506,516,520,525,535,539],{"__ignoreMap":12},[75,502,503],{"class":77,"line":78},[75,504,505],{"class":405},"\u002F\u002F This creates a reference, NOT a clone\n",[75,507,508,510,512,514],{"class":77,"line":85},[75,509,412],{"class":411},[75,511,415],{"class":81},[75,513,418],{"class":411},[75,515,474],{"class":81},[75,517,518],{"class":77,"line":102},[75,519,436],{"emptyLinePlaceholder":435},[75,521,522],{"class":77,"line":116},[75,523,524],{"class":405},"\u002F\u002F Modifying newMsg also modifies the original msg\n",[75,526,527,529,531,533],{"class":77,"line":127},[75,528,446],{"class":81},[75,530,418],{"class":411},[75,532,451],{"class":95},[75,534,454],{"class":81},[75,536,537],{"class":77,"line":457},[75,538,436],{"emptyLinePlaceholder":435},[75,540,541,543,546],{"class":77,"line":462},[75,542,471],{"class":411},[75,544,545],{"class":81}," msg; ",[75,547,548],{"class":405},"\u002F\u002F The original is now changed!\n",[18,550,551],{},"To clone specific properties only:",[66,553,555],{"className":396,"code":554,"language":398,"meta":12,"style":12},"\u002F\u002F Clone selective properties\nvar newMsg = {};\nnewMsg.payload = msg.payload;  \u002F\u002F Copy payload\nnewMsg.topic = msg.topic;      \u002F\u002F Copy topic\n\nreturn newMsg;\n",[72,556,557,562,573,585,598,602],{"__ignoreMap":12},[75,558,559],{"class":77,"line":78},[75,560,561],{"class":405},"\u002F\u002F Clone selective properties\n",[75,563,564,566,568,570],{"class":77,"line":85},[75,565,412],{"class":411},[75,567,415],{"class":81},[75,569,418],{"class":411},[75,571,572],{"class":81}," {};\n",[75,574,575,577,579,582],{"class":77,"line":102},[75,576,446],{"class":81},[75,578,418],{"class":411},[75,580,581],{"class":81}," msg.payload;  ",[75,583,584],{"class":405},"\u002F\u002F Copy payload\n",[75,586,587,590,592,595],{"class":77,"line":116},[75,588,589],{"class":81},"newMsg.topic ",[75,591,418],{"class":411},[75,593,594],{"class":81}," msg.topic;      ",[75,596,597],{"class":405},"\u002F\u002F Copy topic\n",[75,599,600],{"class":77,"line":127},[75,601,436],{"emptyLinePlaceholder":435},[75,603,604,606],{"class":77,"line":457},[75,605,471],{"class":411},[75,607,608],{"class":81}," newMsg;\n",[25,610,612],{"id":611},"adding-new-properties-to-messages","Adding New Properties to Messages",[18,614,615],{},"Node-RED messages are JavaScript objects, making them highly flexible for customization. You can add unlimited properties to carry additional data through your flow—metadata, tags, timestamps, configuration details, and more.",[47,617,293],{"id":618},"using-the-change-node-1",[18,620,621],{},"The Change node allows property addition without coding:",[310,623,624,630,637,648],{},[164,625,626,627,629],{},"Drag a ",[167,628,298],{}," node into your flow and open configuration.",[164,631,632,633,636],{},"Select the ",[167,634,635],{},"Set"," action.",[164,638,639,640,643,644,647],{},"In the ",[167,641,642],{},"Property"," field, enter the new property name (e.g., ",[72,645,646],{},"msg.customData",").",[164,649,639,650,653],{},[167,651,652],{},"To"," field, enter the value—this can be a string, number, boolean, JSONata expression, or reference to another property.",[47,655,390],{"id":656},"using-the-function-node-1",[18,658,659],{},"For programmatic control, add properties in a Function node:",[66,661,663],{"className":396,"code":662,"language":398,"meta":12,"style":12},"\u002F\u002F Add custom properties to the message\nmsg.customData = {\n    description: \"Sensor reading from device A\",\n    timestamp: new Date().toISOString(),\n    location: \"Building 3, Floor 2\"\n};\n\n\u002F\u002F Return the enhanced message\nreturn msg;\n",[72,664,665,670,680,690,710,718,723,727,732],{"__ignoreMap":12},[75,666,667],{"class":77,"line":78},[75,668,669],{"class":405},"\u002F\u002F Add custom properties to the message\n",[75,671,672,675,677],{"class":77,"line":85},[75,673,674],{"class":81},"msg.customData ",[75,676,418],{"class":411},[75,678,679],{"class":81}," {\n",[75,681,682,685,688],{"class":77,"line":102},[75,683,684],{"class":81},"    description: ",[75,686,687],{"class":95},"\"Sensor reading from device A\"",[75,689,99],{"class":81},[75,691,692,695,698,701,704,707],{"class":77,"line":116},[75,693,694],{"class":81},"    timestamp: ",[75,696,697],{"class":411},"new",[75,699,700],{"class":88}," Date",[75,702,703],{"class":81},"().",[75,705,706],{"class":88},"toISOString",[75,708,709],{"class":81},"(),\n",[75,711,712,715],{"class":77,"line":127},[75,713,714],{"class":81},"    location: ",[75,716,717],{"class":95},"\"Building 3, Floor 2\"\n",[75,719,720],{"class":77,"line":457},[75,721,722],{"class":81},"};\n",[75,724,725],{"class":77,"line":462},[75,726,436],{"emptyLinePlaceholder":435},[75,728,729],{"class":77,"line":468},[75,730,731],{"class":405},"\u002F\u002F Return the enhanced message\n",[75,733,735,737],{"class":77,"line":734},9,[75,736,471],{"class":411},[75,738,474],{"class":81},[25,740,742],{"id":741},"deleting-and-moving-message-properties","Deleting and Moving Message Properties",[18,744,745],{},"In addition to adding and cloning properties, you may need to remove or relocate properties within messages.",[47,747,749],{"id":748},"deleting-properties","Deleting Properties",[751,752,293],"h4",{"id":753},"using-the-change-node-2",[18,755,756,757,760],{},"Use the ",[167,758,759],{},"Delete"," action to remove unwanted properties from messages:",[310,762,763,767,772],{},[164,764,314,765,317],{},[167,766,298],{},[164,768,632,769,771],{},[167,770,332],{}," action from the dropdown.",[164,773,639,774,776,777,647],{},[167,775,352],{}," field, specify the property to remove (e.g., ",[72,778,779],{},"msg.tempData",[751,781,390],{"id":782},"using-the-function-node-2",[18,784,785,786,789],{},"To delete properties programmatically in a Function node, use the ",[72,787,788],{},"delete"," operator:",[66,791,793],{"className":396,"code":792,"language":398,"meta":12,"style":12},"\u002F\u002F Delete a single property\ndelete msg.tempData;\n\n\u002F\u002F Delete multiple properties\ndelete msg.tempData;\ndelete msg.oldPayload;\ndelete msg.metadata;\n\nreturn msg;\n",[72,794,795,800,807,811,816,822,829,836,840],{"__ignoreMap":12},[75,796,797],{"class":77,"line":78},[75,798,799],{"class":405},"\u002F\u002F Delete a single property\n",[75,801,802,804],{"class":77,"line":85},[75,803,788],{"class":411},[75,805,806],{"class":81}," msg.tempData;\n",[75,808,809],{"class":77,"line":102},[75,810,436],{"emptyLinePlaceholder":435},[75,812,813],{"class":77,"line":116},[75,814,815],{"class":405},"\u002F\u002F Delete multiple properties\n",[75,817,818,820],{"class":77,"line":127},[75,819,788],{"class":411},[75,821,806],{"class":81},[75,823,824,826],{"class":77,"line":457},[75,825,788],{"class":411},[75,827,828],{"class":81}," msg.oldPayload;\n",[75,830,831,833],{"class":77,"line":462},[75,832,788],{"class":411},[75,834,835],{"class":81}," msg.metadata;\n",[75,837,838],{"class":77,"line":468},[75,839,436],{"emptyLinePlaceholder":435},[75,841,842,844],{"class":77,"line":734},[75,843,471],{"class":411},[75,845,474],{"class":81},[47,847,849],{"id":848},"moving-properties","Moving Properties",[751,851,293],{"id":852},"using-the-change-node-3",[18,854,756,855,858],{},[167,856,857],{},"Move"," action to relocate a property to a new location while removing it from the original location:",[310,860,861,865,869,877],{},[164,862,314,863,317],{},[167,864,298],{},[164,866,632,867,771],{},[167,868,335],{},[164,870,871,872,874,875,647],{},"In the first ",[167,873,352],{}," field, specify the source property (e.g., ",[72,876,179],{},[164,878,639,879,882,883,647],{},[167,880,881],{},"\"to\""," field, specify the destination property (e.g., ",[72,884,885],{},"msg.oldPayload",[751,887,390],{"id":888},"using-the-function-node-3",[18,890,891],{},"To move a property programmatically in a Function node, copy the property to its new location and then delete it from the original:",[66,893,895],{"className":396,"code":894,"language":398,"meta":12,"style":12},"\u002F\u002F Move msg.payload to msg.oldPayload\nmsg.oldPayload = msg.payload;\ndelete msg.payload;\n\n\u002F\u002F Or move a nested property\nmsg.backup = {\n    data: msg.tempData\n};\ndelete msg.tempData;\n\nreturn msg;\n",[72,896,897,902,912,918,922,927,936,941,945,951,956],{"__ignoreMap":12},[75,898,899],{"class":77,"line":78},[75,900,901],{"class":405},"\u002F\u002F Move msg.payload to msg.oldPayload\n",[75,903,904,907,909],{"class":77,"line":85},[75,905,906],{"class":81},"msg.oldPayload ",[75,908,418],{"class":411},[75,910,911],{"class":81}," msg.payload;\n",[75,913,914,916],{"class":77,"line":102},[75,915,788],{"class":411},[75,917,911],{"class":81},[75,919,920],{"class":77,"line":116},[75,921,436],{"emptyLinePlaceholder":435},[75,923,924],{"class":77,"line":127},[75,925,926],{"class":405},"\u002F\u002F Or move a nested property\n",[75,928,929,932,934],{"class":77,"line":457},[75,930,931],{"class":81},"msg.backup ",[75,933,418],{"class":411},[75,935,679],{"class":81},[75,937,938],{"class":77,"line":462},[75,939,940],{"class":81},"    data: msg.tempData\n",[75,942,943],{"class":77,"line":468},[75,944,722],{"class":81},[75,946,947,949],{"class":77,"line":734},[75,948,788],{"class":411},[75,950,806],{"class":81},[75,952,954],{"class":77,"line":953},10,[75,955,436],{"emptyLinePlaceholder":435},[75,957,959,961],{"class":77,"line":958},11,[75,960,471],{"class":411},[75,962,474],{"class":81},[18,964,965,968],{},[167,966,967],{},"Important Note:"," Just like with cloning, if you need to move a property that contains an object or array and want to ensure the original is completely removed from memory, you should clone it first:",[66,970,972],{"className":396,"code":971,"language":398,"meta":12,"style":12},"\u002F\u002F Move with cloning (for objects\u002Farrays)\nmsg.oldPayload = RED.util.cloneMessage(msg.payload);\ndelete msg.payload;\n\nreturn msg;\n",[72,973,974,979,994,1000,1004],{"__ignoreMap":12},[75,975,976],{"class":77,"line":78},[75,977,978],{"class":405},"\u002F\u002F Move with cloning (for objects\u002Farrays)\n",[75,980,981,983,985,987,989,991],{"class":77,"line":85},[75,982,906],{"class":81},[75,984,418],{"class":411},[75,986,421],{"class":110},[75,988,424],{"class":81},[75,990,427],{"class":88},[75,992,993],{"class":81},"(msg.payload);\n",[75,995,996,998],{"class":77,"line":102},[75,997,788],{"class":411},[75,999,911],{"class":81},[75,1001,1002],{"class":77,"line":116},[75,1003,436],{"emptyLinePlaceholder":435},[75,1005,1006,1008],{"class":77,"line":127},[75,1007,471],{"class":411},[75,1009,474],{"class":81},[18,1011,1012],{},"This ensures that the moved property is independent and modifications to the new location won't affect any lingering references to the old location.",[25,1014,1016],{"id":1015},"handling-json-messages","Handling JSON Messages",[18,1018,1019,1020,1025],{},"Working with ",[55,1021,1024],{"href":1022,"rel":1023},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FLearn\u002FJavaScript\u002FObjects\u002FJSON",[59],"JSON"," is common in Node-RED, especially with APIs and IoT data. JSON (JavaScript Object Notation) is a lightweight data-exchange format.",[18,1027,1028],{},"Two forms of JSON exist in Node-RED:",[310,1030,1031,1037],{},[164,1032,1033,1036],{},[167,1034,1035],{},"JSON Object",": A structured JavaScript object that can be directly manipulated—access properties, modify values, pass through nodes seamlessly.",[164,1038,1039,1042],{},[167,1040,1041],{},"JSON String",": A serialized JSON representation, commonly used when transmitting data between systems. Unlike objects, JSON strings cannot be directly manipulated as structured data.",[47,1044,1046],{"id":1045},"converting-json-string-to-json-object","Converting JSON String to JSON Object",[18,1048,1049,1050,1052],{},"To work with a JSON string as a JavaScript object, convert it using the ",[167,1051,1024],{}," node. This node parses the string into a usable object structure.",[18,1054,1055],{},"Steps:",[310,1057,1058,1064,1067,1070],{},[164,1059,1060,1061,1063],{},"Drag the ",[167,1062,1024],{}," node onto the canvas.",[164,1065,1066],{},"Double-click to configure.",[164,1068,1069],{},"Set the action to \"Always convert to JavaScript Object\" and click Done.",[164,1071,1072],{},"Connect the JSON node between the source node (sending the JSON string) and the destination node (requiring the parsed object).",[18,1074,1075,1076,386],{},"The JSON node automatically converts incoming JSON strings into JavaScript objects. For more details, see the ",[55,1077,1079],{"href":1078},"\u002Fnode-red\u002Fcore-nodes\u002Fjson\u002F","JSON node documentation",[25,1081,1083],{"id":1082},"common-mistakes-to-avoid","Common Mistakes to Avoid",[18,1085,1086],{},"Avoiding these pitfalls ensures smooth flow operation:",[47,1088,1090],{"id":1089},"_1-adding-properties-to-non-object-types","1. Adding Properties to Non-Object Types",[18,1092,1093],{},"Attempting to add properties to primitive types (strings, numbers) causes errors.",[18,1095,1096],{},[167,1097,1098],{},"Incorrect:",[66,1100,1102],{"className":68,"code":1101,"language":70,"meta":12,"style":12},"msg.payload = 'stringValue';\nmsg.payload.newProperty = 'value';  \u002F\u002F Error: Cannot add property to string\nreturn msg;\n",[72,1103,1104,1116,1132],{"__ignoreMap":12},[75,1105,1106,1109,1111,1114],{"class":77,"line":78},[75,1107,1108],{"class":81},"msg.payload ",[75,1110,418],{"class":411},[75,1112,1113],{"class":95}," 'stringValue'",[75,1115,454],{"class":81},[75,1117,1118,1121,1123,1126,1129],{"class":77,"line":85},[75,1119,1120],{"class":81},"msg.payload.newProperty ",[75,1122,418],{"class":411},[75,1124,1125],{"class":95}," 'value'",[75,1127,1128],{"class":81},";  ",[75,1130,1131],{"class":405},"\u002F\u002F Error: Cannot add property to string\n",[75,1133,1134,1136],{"class":77,"line":102},[75,1135,471],{"class":411},[75,1137,474],{"class":81},[18,1139,1140],{},[167,1141,1142],{},"Correct:",[66,1144,1146],{"className":68,"code":1145,"language":70,"meta":12,"style":12},"msg.payload = {};  \u002F\u002F Initialize as object\nmsg.payload.newProperty = 'value';\nreturn msg;\n",[72,1147,1148,1160,1170],{"__ignoreMap":12},[75,1149,1150,1152,1154,1157],{"class":77,"line":78},[75,1151,1108],{"class":81},[75,1153,418],{"class":411},[75,1155,1156],{"class":81}," {};  ",[75,1158,1159],{"class":405},"\u002F\u002F Initialize as object\n",[75,1161,1162,1164,1166,1168],{"class":77,"line":85},[75,1163,1120],{"class":81},[75,1165,418],{"class":411},[75,1167,1125],{"class":95},[75,1169,454],{"class":81},[75,1171,1172,1174],{"class":77,"line":102},[75,1173,471],{"class":411},[75,1175,474],{"class":81},[18,1177,1178,1179,1181],{},"This commonly occurs when an Inject node sends ",[72,1180,179],{}," as a string or number, then a Change node attempts to add properties to it.",[18,1183,1184,1188],{},[35,1185],{"alt":1186,"dataZoomable":12,"src":1187},"Showing the common mistake: adding property to non-object","\u002Fnode-red-media\u002Fgetting-started\u002Fimages\u002Fmistake1.gif",[40,1189,1190],{},"Incorrect: Adding properties to a non-object type",[18,1192,1193,1197],{},[35,1194],{"alt":1195,"dataZoomable":12,"src":1196},"Correct approach to prevent the error","\u002Fnode-red-media\u002Fgetting-started\u002Fimages\u002Fmistake-1-solution.gif",[40,1198,1199],{},"Correct: Initialize as object before adding properties",[47,1201,1203],{"id":1202},"_2-overwriting-the-entire-message-object","2. Overwriting the Entire Message Object",[18,1205,1206,1207,1209,1210,137,1212,1214],{},"Accidentally replacing the entire ",[72,1208,155],{}," object loses important properties like ",[72,1211,197],{},[72,1213,205],{},", and custom metadata.",[18,1216,1217],{},[167,1218,1098],{},[66,1220,1222],{"className":68,"code":1221,"language":70,"meta":12,"style":12},"msg = { newProperty: 'value' };  \u002F\u002F Destroys existing msg structure\nreturn msg;\n",[72,1223,1224,1243],{"__ignoreMap":12},[75,1225,1226,1229,1231,1234,1237,1240],{"class":77,"line":78},[75,1227,1228],{"class":81},"msg ",[75,1230,418],{"class":411},[75,1232,1233],{"class":81}," { newProperty: ",[75,1235,1236],{"class":95},"'value'",[75,1238,1239],{"class":81}," };  ",[75,1241,1242],{"class":405},"\u002F\u002F Destroys existing msg structure\n",[75,1244,1245,1247],{"class":77,"line":85},[75,1246,471],{"class":411},[75,1248,474],{"class":81},[18,1250,1251],{},[167,1252,1142],{},[66,1254,1256],{"className":68,"code":1255,"language":70,"meta":12,"style":12},"msg.newProperty = 'value';  \u002F\u002F Preserves existing properties\nreturn msg;\n",[72,1257,1258,1272],{"__ignoreMap":12},[75,1259,1260,1263,1265,1267,1269],{"class":77,"line":78},[75,1261,1262],{"class":81},"msg.newProperty ",[75,1264,418],{"class":411},[75,1266,1125],{"class":95},[75,1268,1128],{"class":81},[75,1270,1271],{"class":405},"\u002F\u002F Preserves existing properties\n",[75,1273,1274,1276],{"class":77,"line":85},[75,1275,471],{"class":411},[75,1277,474],{"class":81},[47,1279,1281],{"id":1280},"_3-returning-incorrect-data-types","3. Returning Incorrect Data Types",[18,1283,1284],{},"Node-RED expects function nodes to return message objects. Returning primitives breaks the flow.",[18,1286,1287],{},[167,1288,1098],{},[66,1290,1292],{"className":68,"code":1291,"language":70,"meta":12,"style":12},"return \"some string\";  \u002F\u002F Error: Not a valid message\n",[72,1293,1294],{"__ignoreMap":12},[75,1295,1296,1298,1301,1303],{"class":77,"line":78},[75,1297,471],{"class":411},[75,1299,1300],{"class":95}," \"some string\"",[75,1302,1128],{"class":81},[75,1304,1305],{"class":405},"\u002F\u002F Error: Not a valid message\n",[18,1307,1308],{},[167,1309,1142],{},[66,1311,1313],{"className":68,"code":1312,"language":70,"meta":12,"style":12},"msg.payload = \"some string\";\nreturn msg;\n",[72,1314,1315,1325],{"__ignoreMap":12},[75,1316,1317,1319,1321,1323],{"class":77,"line":78},[75,1318,1108],{"class":81},[75,1320,418],{"class":411},[75,1322,1300],{"class":95},[75,1324,454],{"class":81},[75,1326,1327,1329],{"class":77,"line":85},[75,1328,471],{"class":411},[75,1330,474],{"class":81},[47,1332,1334],{"id":1333},"_4-forgetting-to-return-the-message","4. Forgetting to Return the Message",[18,1336,1337],{},"In Function nodes, forgetting the return statement halts the flow at that node.",[18,1339,1340],{},[167,1341,1098],{},[66,1343,1345],{"className":68,"code":1344,"language":70,"meta":12,"style":12},"msg.payload = msg.payload * 2;\n\u002F\u002F Missing return statement - flow stops here\n",[72,1346,1347,1364],{"__ignoreMap":12},[75,1348,1349,1351,1353,1356,1359,1362],{"class":77,"line":78},[75,1350,1108],{"class":81},[75,1352,418],{"class":411},[75,1354,1355],{"class":81}," msg.payload ",[75,1357,1358],{"class":411},"*",[75,1360,1361],{"class":110}," 2",[75,1363,454],{"class":81},[75,1365,1366],{"class":77,"line":85},[75,1367,1368],{"class":405},"\u002F\u002F Missing return statement - flow stops here\n",[18,1370,1371],{},[167,1372,1142],{},[66,1374,1376],{"className":68,"code":1375,"language":70,"meta":12,"style":12},"msg.payload = msg.payload * 2;\nreturn msg;  \u002F\u002F Flow continues\n",[72,1377,1378,1392],{"__ignoreMap":12},[75,1379,1380,1382,1384,1386,1388,1390],{"class":77,"line":78},[75,1381,1108],{"class":81},[75,1383,418],{"class":411},[75,1385,1355],{"class":81},[75,1387,1358],{"class":411},[75,1389,1361],{"class":110},[75,1391,454],{"class":81},[75,1393,1394,1396,1399],{"class":77,"line":85},[75,1395,471],{"class":411},[75,1397,1398],{"class":81}," msg;  ",[75,1400,1401],{"class":405},"\u002F\u002F Flow continues\n",[18,1403,1404],{},"By mastering Node-RED message handling and avoiding common mistakes, you can build robust, efficient workflows. Understanding JSON conversion, message cloning, and proper property management ensures smooth data flow between nodes and maintainable, error-free applications.",[1406,1407,1408],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":12,"searchDepth":85,"depth":85,"links":1410},[1411,1414,1415,1416,1420,1424,1428,1431],{"id":27,"depth":85,"text":28,"children":1412},[1413],{"id":49,"depth":102,"text":50},{"id":148,"depth":85,"text":149},{"id":212,"depth":85,"text":213},{"id":285,"depth":85,"text":286,"children":1417},[1418,1419],{"id":292,"depth":102,"text":293},{"id":389,"depth":102,"text":390},{"id":611,"depth":85,"text":612,"children":1421},[1422,1423],{"id":618,"depth":102,"text":293},{"id":656,"depth":102,"text":390},{"id":741,"depth":85,"text":742,"children":1425},[1426,1427],{"id":748,"depth":102,"text":749},{"id":848,"depth":102,"text":849},{"id":1015,"depth":85,"text":1016,"children":1429},[1430],{"id":1045,"depth":102,"text":1046},{"id":1082,"depth":85,"text":1083,"children":1432},[1433,1434,1435,1436],{"id":1089,"depth":102,"text":1090},{"id":1202,"depth":102,"text":1203},{"id":1280,"depth":102,"text":1281},{"id":1333,"depth":102,"text":1334},"A comprehensive guide to working with Node-RED messages, ensuring error-free flows and optimized data handling.","md",{},"\u002Fnode-red\u002Fgetting-started\u002Fnode-red-messages",{"title":5,"description":1437},"node-red\u002Fgetting-started\u002Fnode-red-messages","Dlicr1yss6rWGs7gUFInnAatFAZB421oaHfK6pSNOOQ",1780070557229]