Search code examples
node.jsjsonnode-red

How can I pick-up a payload data in a nestd payload?


I have a couple of ingress payload like

{"topic":"homepi/dht11repub", "payload": 
     "{ \"timestamp\": \"2018-11-26T08:50:55Z\", 
     \"Temperature\": 17.0, 
     \"humidity\": 92.0 }",  
  "qos":0,"retain":false,"_msgid":"b7af75be.485088"}

I wanna pick the data in node-red function. I Have tried

var t =msg.payload
payload= t.payload
return msg

and

msg.payload[payload]

but it does not work. Does anybody know how can I solve this problem?


Solution

  • Pass the incoming message through the JSON node first to convert it to a JSON object.

    If you still need it as a string afterwards you can pass it through another JSON node that will convert it back to a string.