How can i populated value to JSON payload

Hi,
i do have a function node where i build a JSON message based on the set points.

However as you observer i do have a parent node "01" this refers to the data packet which i receive from the

global.get("currentDataPacket")

which will increment and give a current data packet number.
Is there a way how i can send

global.get("currentDataPacket")

value instead
"01"?

msg.payload =
{
    "state": {
        "response": {
            "home": {
                "01": {
                    "temperature": global.get("currentTemp"),
                    "humidity": global.get("currentHumidty")
                }
            }
        }    
    }    
}
msg.payload =
{
    "state": {
        "response": {
            "home": {
                 [global.get("currentDataPacket")]: {
                    "temperature": global.get("currentTemp"),
                    "humidity": global.get("currentHumidty")
                }
            }
        }    
    }    
}

In fact that is not JSON, JSON is always a string. You are creating a javascript object.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.