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

auto mode to auto parse string to JS Object

This commit is contained in:
Stephen McLaughlin 2022-04-14 16:39:35 +01:00 committed by Steve-Mcl
parent 8f5d3dc49c
commit 78f456911a
8 changed files with 15 additions and 12 deletions

View File

@ -235,8 +235,7 @@ module.exports = function(RED) {
if (v5isUtf8 || isUtf8(payload)) {
try {
payload = JSON.parse(payload.toString());
}
catch(e) {
} catch(e) {
node.error(RED._("mqtt.errors.invalid-json-parse"),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return;
}
}
@ -255,19 +254,23 @@ module.exports = function(RED) {
case "object":
try {
payload = JSON.parse(payload.toString());
}
catch(e) {
} catch(e) {
node.error(RED._("mqtt.errors.invalid-json-parse"),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return;
}
break;
default:
if (v5isUtf8 || isUtf8(payload)) {
if (v5isUtf8 || isUtf8(payload)) {
payload = payload.toString(); //auto String
}
break;
}
} else if (isUtf8(payload)) {
payload = payload.toString(); //auto String
try {
payload = JSON.parse(payload);
} catch(e) {
/* mute error - it simply isnt JSON, just leave payload as a string */
}
} //else {
//leave as buffer
//}

View File

@ -422,7 +422,7 @@
"buffer": "Einen binären Buffer",
"string": "Ein String",
"base64": "Ein Base64-kodierter String",
"auto": "Auto-Erkennung (string oder buffer)",
"auto": "Auto-Erkennung (parsed JSON-Objekt, string oder buffer)",
"json": "Ein analysiertes (parsed) JSON-Objekt"
},
"true": "wahr",

View File

@ -454,7 +454,7 @@
"buffer": "a Buffer",
"string": "a String",
"base64": "a Base64 encoded string",
"auto": "auto-detect (string or buffer)",
"auto": "auto-detect (parsed JSON object, string or buffer)",
"json": "a parsed JSON object"
},
"true": "true",

View File

@ -454,7 +454,7 @@
"buffer": "バイナリバッファ",
"string": "文字列",
"base64": "Base64文字列",
"auto": "自動判定(文字列もしくはバイナリバッファ)",
"auto": "自動判定(JSONオブジェクト、文字列もしくはバイナリバッファ)",
"json": "JSONオブジェクト"
},
"true": "する",

View File

@ -361,7 +361,7 @@
"buffer": "바이너리 버퍼",
"string": "문자열",
"base64": "Base64문자열",
"auto": "자동판정(문자열혹은 바이너리버퍼)",
"auto": "자동판정(JSON오브젝트, 문자열혹은 바이너리버퍼)",
"json": "JSON오브젝트"
},
"true": "한다",

View File

@ -384,7 +384,7 @@
"buffer": "буфер",
"string": "строка",
"base64": "строка в кодировке Base64",
"auto": "автоопределение (строка или буфер)",
"auto": "автоопределение (разобрать объект JSON, строка или буфер)",
"json": "объект JSON"
},
"true": "да",

View File

@ -381,7 +381,7 @@
"buffer": "Buffer",
"string": "字符串",
"base64": "Base64编码字符串",
"auto": "自动检测 (字符串或buffer)",
"auto": "自动检测 (已解析的JSON对象、字符串或buffer)",
"json": "解析的JSON对象"
},
"true": "是",

View File

@ -385,7 +385,7 @@
"buffer": "Buffer",
"string": "字串",
"base64": "Base64編碼字串",
"auto": "自動檢測 (字符串或buffer)",
"auto": "自动检测 (已解析的JSON对象、字符串或buffer)",
"json": "解析的JSON對象"
},
"true": "是",