1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow JSON node to handle array type

This commit is contained in:
Dave Conway-Jones 2015-10-02 17:30:23 +01:00
parent 9932d34304
commit 83a3642c0e
2 changed files with 10 additions and 4 deletions

View File

@ -488,7 +488,8 @@
"json": {
"errors": {
"dropped-object": "Ignored non-object payload",
"dropped": "Ignored unsupported payload type"
"dropped": "Ignored unsupported payload type",
"dropped-error": "Failed to convert payload"
}
},
"xml": {

View File

@ -31,9 +31,14 @@ module.exports = function(RED) {
catch(e) { node.error(e.message,msg); }
}
else if (typeof msg.payload === "object") {
if ((!Buffer.isBuffer(msg.payload)) && (!util.isArray(msg.payload))) {
msg.payload = JSON.stringify(msg.payload);
node.send(msg);
if (!Buffer.isBuffer(msg.payload)) {
try {
msg.payload = JSON.stringify(msg.payload);
node.send(msg);
}
catch(e) {
node.error(RED._("json.errors.dropped-error"));
}
}
else { node.warn(RED._("json.errors.dropped-object")); }
}