Merge pull request #3296 from node-red/Json-try-parse-buffer

Let JSON node attempt to parse buffer if it contains a valid string
This commit is contained in:
Nick O'Leary
2022-01-12 18:58:02 +00:00
committed by GitHub
2 changed files with 67 additions and 19 deletions

View File

@@ -49,7 +49,11 @@ module.exports = function(RED) {
}
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
if (typeof value === "string") {
if (typeof value === "string" || Buffer.isBuffer(value)) {
// if (Buffer.isBuffer(value) && node.action !== "obj") {
// node.warn(RED._("json.errors.dropped")); done();
// }
// else
if (node.action === "" || node.action === "obj") {
try {
RED.util.setMessageProperty(msg,node.property,JSON.parse(value));