node-red parsing a json string to msg.payload

Viewed 33399

Noob question

I am using the snmp function to collect data via oid lists. I have extracted the data and used the json function to parse the data into a json string seen below.

msg.payload : string[81] "[{"oid":"1.3.6.1.4.1.38783.3.3.1.1.1.0","type":2,"value":53800,"tstr":"Integer"}]"

I am trying to write a function to strip out "value":53800 from this string and output it in msg.payload.

I have tried below but it returns

"TypeError: Cannot assign to read only property '_msgid' of "value":53700,"tstr":"Integer"}]"

var msg = msg.payload;
var value = msg.substr(49,62);

return value;
2 Answers

For your JSON the following code will work in the function:

var value = msg.payload.value;
msg.payload = value;
return msg;
Related