From dac7830bd4b6f9a50a15b1a8fb11d341be5cb8cd Mon Sep 17 00:00:00 2001 From: Hiroyasu Nishiyama Date: Tue, 3 Nov 2020 20:06:18 +0900 Subject: [PATCH] add example for JSON node --- ...vert JSON string to JavaScript object.json | 92 ++++++++++ ...vert JavaScript object to JSON string.json | 92 ++++++++++ .../json/03 - Validate input JSON string.json | 160 ++++++++++++++++++ 3 files changed, 344 insertions(+) create mode 100644 packages/node_modules/@node-red/nodes/examples/parser/json/01 - Convert JSON string to JavaScript object.json create mode 100644 packages/node_modules/@node-red/nodes/examples/parser/json/02 - Convert JavaScript object to JSON string.json create mode 100644 packages/node_modules/@node-red/nodes/examples/parser/json/03 - Validate input JSON string.json diff --git a/packages/node_modules/@node-red/nodes/examples/parser/json/01 - Convert JSON string to JavaScript object.json b/packages/node_modules/@node-red/nodes/examples/parser/json/01 - Convert JSON string to JavaScript object.json new file mode 100644 index 000000000..c95e71a7d --- /dev/null +++ b/packages/node_modules/@node-red/nodes/examples/parser/json/01 - Convert JSON string to JavaScript object.json @@ -0,0 +1,92 @@ +[ + { + "id": "9976e95d.2f8398", + "type": "inject", + "z": "4b63452d.672afc", + "name": "", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 240, + "y": 180, + "wires": [ + [ + "d94fc083.49d87" + ] + ] + }, + { + "id": "6684abb1.8eb454", + "type": "comment", + "z": "4b63452d.672afc", + "name": "Convert JSON string to JS object", + "info": "JSON node can convert JSON string to JavaScript object.", + "x": 250, + "y": 120, + "wires": [] + }, + { + "id": "d94fc083.49d87", + "type": "template", + "z": "4b63452d.672afc", + "name": "JSON string", + "field": "payload", + "fieldType": "msg", + "format": "json", + "syntax": "plain", + "template": "{\n \"kind\": \"Apple\",\n \"price\": 100,\n \"origin\": \"Canada\"\n}", + "output": "str", + "x": 410, + "y": 180, + "wires": [ + [ + "1a3dc54a.78598b" + ] + ] + }, + { + "id": "8950a55d.023988", + "type": "debug", + "z": "4b63452d.672afc", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "false", + "statusVal": "", + "statusType": "auto", + "x": 730, + "y": 180, + "wires": [] + }, + { + "id": "1a3dc54a.78598b", + "type": "json", + "z": "4b63452d.672afc", + "name": "", + "property": "payload", + "action": "", + "pretty": false, + "x": 570, + "y": 180, + "wires": [ + [ + "8950a55d.023988" + ] + ] + } +] \ No newline at end of file diff --git a/packages/node_modules/@node-red/nodes/examples/parser/json/02 - Convert JavaScript object to JSON string.json b/packages/node_modules/@node-red/nodes/examples/parser/json/02 - Convert JavaScript object to JSON string.json new file mode 100644 index 000000000..a10cc75b9 --- /dev/null +++ b/packages/node_modules/@node-red/nodes/examples/parser/json/02 - Convert JavaScript object to JSON string.json @@ -0,0 +1,92 @@ +[ + { + "id": "cb13761f.56c328", + "type": "inject", + "z": "4b63452d.672afc", + "name": "", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 240, + "y": 380, + "wires": [ + [ + "c607642a.78c3c8" + ] + ] + }, + { + "id": "180b1e22.0074e2", + "type": "comment", + "z": "4b63452d.672afc", + "name": "Convert JS object to JSON string", + "info": "JSON node can convert JavaScript object to JSON string.", + "x": 250, + "y": 320, + "wires": [] + }, + { + "id": "c607642a.78c3c8", + "type": "template", + "z": "4b63452d.672afc", + "name": "JS object", + "field": "payload", + "fieldType": "msg", + "format": "json", + "syntax": "plain", + "template": "{\n \"kind\": \"Apple\",\n \"price\": 100,\n \"origin\": \"Canada\"\n}", + "output": "json", + "x": 400, + "y": 380, + "wires": [ + [ + "bf309844.fa12e8" + ] + ] + }, + { + "id": "5b6b130b.72a14c", + "type": "debug", + "z": "4b63452d.672afc", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "false", + "statusVal": "", + "statusType": "auto", + "x": 730, + "y": 380, + "wires": [] + }, + { + "id": "bf309844.fa12e8", + "type": "json", + "z": "4b63452d.672afc", + "name": "", + "property": "payload", + "action": "", + "pretty": false, + "x": 570, + "y": 380, + "wires": [ + [ + "5b6b130b.72a14c" + ] + ] + } +] \ No newline at end of file diff --git a/packages/node_modules/@node-red/nodes/examples/parser/json/03 - Validate input JSON string.json b/packages/node_modules/@node-red/nodes/examples/parser/json/03 - Validate input JSON string.json new file mode 100644 index 000000000..6271f00c6 --- /dev/null +++ b/packages/node_modules/@node-red/nodes/examples/parser/json/03 - Validate input JSON string.json @@ -0,0 +1,160 @@ +[ + { + "id": "2b18621b.e2670e", + "type": "inject", + "z": "4b63452d.672afc", + "name": "OK", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 230, + "y": 580, + "wires": [ + [ + "5986faee.aef954" + ] + ] + }, + { + "id": "59acf99.9a92308", + "type": "comment", + "z": "4b63452d.672afc", + "name": "Validate input JSON string", + "info": "JSON node can validate input JSON string using [JSON schema](https://json-schema.org/) when converting to JavaScript object.", + "x": 230, + "y": 520, + "wires": [] + }, + { + "id": "5986faee.aef954", + "type": "template", + "z": "4b63452d.672afc", + "name": "JSON string", + "field": "payload", + "fieldType": "msg", + "format": "json", + "syntax": "plain", + "template": "{\n \"kind\": \"Apple\",\n \"price\": 100,\n \"origin\": \"Canada\"\n}", + "output": "str", + "x": 410, + "y": 580, + "wires": [ + [ + "f8a67c6d.4f1f1" + ] + ] + }, + { + "id": "ca27c92c.ad7cb8", + "type": "debug", + "z": "4b63452d.672afc", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "payload", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "x": 910, + "y": 580, + "wires": [] + }, + { + "id": "2fad9978.ea1916", + "type": "json", + "z": "4b63452d.672afc", + "name": "", + "property": "payload", + "action": "", + "pretty": false, + "x": 750, + "y": 580, + "wires": [ + [ + "ca27c92c.ad7cb8" + ] + ] + }, + { + "id": "f8a67c6d.4f1f1", + "type": "template", + "z": "4b63452d.672afc", + "name": "Schema", + "field": "schema", + "fieldType": "msg", + "format": "json", + "syntax": "plain", + "template": "{\n \"type\": \"object\",\n \"properties\": {\n \"kind\": {\n \"type\": \"string\"\n },\n \"price\": {\n \"type\": \"number\"\n },\n \"origin\": {\n \"type\": \"string\"\n }\n }\n}", + "output": "json", + "x": 590, + "y": 580, + "wires": [ + [ + "2fad9978.ea1916" + ] + ] + }, + { + "id": "8337e847.ac18d8", + "type": "inject", + "z": "4b63452d.672afc", + "name": "NG", + "props": [ + { + "p": "payload" + }, + { + "p": "topic", + "vt": "str" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "", + "payloadType": "date", + "x": 230, + "y": 660, + "wires": [ + [ + "fa14d8bf.1ac938" + ] + ] + }, + { + "id": "fa14d8bf.1ac938", + "type": "template", + "z": "4b63452d.672afc", + "name": "JSON string", + "field": "payload", + "fieldType": "msg", + "format": "json", + "syntax": "plain", + "template": "{\n \"kind\": \"Apple\",\n \"price\": \"100\",\n \"origin\": \"Canada\"\n}", + "output": "str", + "x": 410, + "y": 660, + "wires": [ + [ + "f8a67c6d.4f1f1" + ] + ] + } +] \ No newline at end of file