Node-RED Joinノード ガイド

☁️ クラウドOK 環境とは?

このガイドでは、Node-REDのJoinノードについて、初心者の方でも理解できるように詳しく説明します。

1. Joinノードとは?

「Join」って何?

Joinノードは、複数のメッセージを1つのメッセージに結合するノードです。 日常生活で例えると、パズルのピースを組み合わせて1枚の絵を完成させるようなものです。

パズルの組み立てに例えると:

基本的な動作

Split →→→ 処理 →→→ Join → Debug

Joinノードは、複数のメッセージを受け取り、それらを1つのメッセージにまとめて出力します。 Splitノードで分割したメッセージを再結合したり、異なるソースからのデータを統合したりできます。

入力(3メッセージ)
"Apple" → "Orange" → "Banana"
↓ Join ↓
出力(1メッセージ)
["Apple", "Orange", "Banana"]

動作を図で見る

join ノードは、複数の msg を 1 つにまとめます。「自動」モードは split と組にして使い、分けたものを元に戻します。

msg 1payload: 10parts.index: 0 count: 3msg 2payload: 20parts.index: 1 count: 3msg 3payload: 30parts.index: 2 count: 3join(自動)出ていく msgpayload: [10, 20, 30]3 つそろったら 1 つにまとめる
parts の情報を頼りに、分かれた msg を元の配列に戻す

「手動」モードでは、まとめ方と件数を自分で決めます。

msg 1topic: "temp"payload: 25msg 2topic: "hum"payload: 60join(手動)出ていく msgpayload: { temp: 25, hum: 60}
topic をキー、payload を値にして、2 件を 1 つのオブジェクトにまとめる

2. Joinノードの3つのモード

自動 Automatic

Splitノードと連携して自動的に再結合

msg.partsを使用して 元の形式に復元

手動 Manual

メッセージ数やタイムアウトを指定して結合

文字列/配列/オブジェクト 形式を選択可能

Reduce Reduce

JSONata式でメッセージを集計・変換

合計、平均、配列変換 など柔軟な処理

設定項目一覧

Join ノードの設定欄は、上部で選ぶ「動作」(モード)に応じて表示が切り替わる。まず全モード共通の項目を決め、続いて選んだモードの専用項目を設定する。

共通(モードの選択)

設定項目 説明 既定値
名前 ノードに付ける表示名。指定するとフロー上のラベルになる。 (空)
動作 結合のモードを選ぶ。自動は split が付けた msg.parts を頼りに元の形へ戻す。手動は出力形式と送信タイミングを自分で指定する。列の集約(Reduce)は JSONata 式でメッセージ列を 1 つの値へ畳み込む。 自動

「動作」=手動のときの項目

設定項目 説明 既定値
結合 結合の対象にするメッセージプロパティ。通常は msg.payload。「メッセージ全体」を選ぶと msg ごと結合する。 msg.payload
出力 結合結果をどの形にまとめるか(種類は下表)。 key/valueオブジェクト
使用する値(をキーとして使用) 出力が「key/valueオブジェクト」のとき、どのプロパティをキーにするか。既定は msg.topic。 topic
連結文字 出力が「文字列」「バッファ」のとき、各値の間に挟む区切り。 \n(改行)
既存のmsg.partsプロパティを使用 入力に付いている msg.parts のシーケンス情報を使って、結合の順序と件数を判断する。 オフ

メッセージ送信: 手動モードでは、次のいずれかの条件が満たされたときに結合結果を送り出す(条件は併用できる)。

設定項目 説明 既定値
指定数のメッセージパーツを受信後 受信した件数がこの数に達したら送信する。 (空)
後続のメッセージ毎 件数に達した後も、メッセージを受け取るたびに最新の結合結果を送り続ける(出力が key/valueオブジェクト・結合オブジェクトのときだけ表示)。 オフ
最初のメッセージ受信からのタイムアウト後 最初の受信から指定した秒数が過ぎたら、その時点までの分で送信する。 (空)
msg.complete プロパティが設定されたメッセージ受信後 msg.complete を持つメッセージを受け取った時点で送信する(エディター上は設定欄ではなく説明として表示される)。 —

「出力」の種類

選択肢 結合結果
文字列 各値を連結文字でつないだ 1 つの文字列。
バッファ 各値を連結した 1 つのバイナリバッファ。
配列 受信順に並べた配列。
key/valueオブジェクト 「使用する値」で指定したキーを見出しにしたオブジェクト。
結合オブジェクト 各メッセージのオブジェクトを 1 つにマージしたオブジェクト。

「動作」=列の集約(Reduce)のときの項目

設定項目 説明 既定値
集約式 メッセージごとに評価する JSONata 式。累積値 $A に現在値を足し込むなど、畳み込みの本体を書く。 (未設定)
初期値 $A の初期値。型も選べる。 (未設定)
最終調整式 全メッセージの処理後に 1 度だけ評価し、結果を仕上げる JSONata 式。合計を件数 $N で割って平均にするなど。 (未設定)
評価を逆順に行う (最後から最初) メッセージ列を末尾から先頭へ向けて畳み込む。 オフ

msg.partsオブジェクト

Splitノードが付与するmsg.parts情報を使って、Joinノードは自動的にメッセージを再結合します。

msg.parts = { id: "abc123", // 分割グループの識別子 index: 0, // このメッセージの順番(0から) count: 3, // 総分割数 type: "array", // 元のデータ型 key: "Apple" // オブジェクト分割時のキー名 }

3. 実用的な使用パターン

サンプルフローのインポート方法:

  1. 下のサンプルフローJSONをコピー
  2. Node-REDエディタで メニュー → 読み込み を選択
  3. JSONをペーストして「読み込み」をクリック

このサンプルフローには、以下で説明する全パターンの実例が含まれています。

サンプルフローは、Node-RED本体に同梱されている公式サンプル3つ(「Automatic join mode」「Manual join mode」「Reduce sequence mode」)を1つのタブにまとめ、名前の無かった inject ノードと debug ノードに日本語の名前を付けたものです。エディタの メニュー → 読み込み → サンプル → node-red → sequence → join からも、元の3つを開けます。

📋 サンプルフロー(クリックで展開)

参照元:NodeREDエディター内サンプルフロー

[ { "id": "7c9d326a56fe84a8", "type": "tab", "label": "join", "disabled": false, "info": "", "env": [] }, { "id": "afe74de5.58488", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Example: Automatic Mode", "info": "Join node can be used to join payload of messages into single message payload. In automatic mode, it uses `parts` property to decide sequence of messages to join.", "x": 150, "y": 60, "wires": [] }, { "id": "d0c8c78e.1281e8", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例1: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 180, "wires": [ [ "c59ac70d.bb9c58" ] ] }, { "id": "c59ac70d.bb9c58", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 180, "wires": [ [ "21829618.af5b0a" ] ] }, { "id": "d6c9fe0.d34ad", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": "false", "timeout": "", "count": "", "reduceRight": false, "x": 630, "y": 180, "wires": [ [ "8defdbb8.aa9c08" ] ] }, { "id": "21829618.af5b0a", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 180, "wires": [ [ "d6c9fe0.d34ad" ] ] }, { "id": "8defdbb8.aa9c08", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例1: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 180, "wires": [] }, { "id": "d96759bf.eabe38", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join message sequence created by split node", "info": "", "x": 250, "y": 120, "wires": [] }, { "id": "a46bcdd3.db621", "type": "csv", "z": "7c9d326a56fe84a8", "name": "", "sep": ",", "hdrin": true, "hdrout": "", "multi": "one", "ret": "\\n", "temp": "", "skip": "0", "strings": true, "include_empty_strings": "", "include_null_values": "", "x": 490, "y": 340, "wires": [ [ "5d1c8a1e.691f74" ] ] }, { "id": "65bf1807.dafad8", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例2: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 340, "wires": [ [ "3640a5ef.f1e0ea" ] ] }, { "id": "3640a5ef.f1e0ea", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "name,price\nApple,100\nOrange,80\nBanana,120\nKiwi,50", "output": "str", "x": 350, "y": 340, "wires": [ [ "a46bcdd3.db621" ] ] }, { "id": "5d1c8a1e.691f74", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": "false", "timeout": "", "count": "", "reduceRight": false, "x": 630, "y": 340, "wires": [ [ "457ab3c9.7301ec" ] ] }, { "id": "457ab3c9.7301ec", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例2: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 340, "wires": [] }, { "id": "d9f508c1.916c18", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join message sequence created by csv node", "info": "", "x": 250, "y": 280, "wires": [] }, { "id": "28970739.29e728", "type": "csv", "z": "7c9d326a56fe84a8", "name": "", "sep": ",", "hdrin": true, "hdrout": "", "multi": "one", "ret": "\\n", "temp": "", "skip": "0", "strings": true, "include_empty_strings": "", "include_null_values": "", "x": 490, "y": 500, "wires": [ [ "bbc984d8.be42d8" ] ] }, { "id": "c8297669.559348", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例3: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 500, "wires": [ [ "2f8f819f.3371be" ] ] }, { "id": "2f8f819f.3371be", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "name,price\nApple,100\nOrange,80\nBanana,120\nKiwi,50", "output": "str", "x": 350, "y": 500, "wires": [ [ "28970739.29e728" ] ] }, { "id": "716ea12e.1edb6", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": "false", "timeout": "", "count": "", "reduceRight": false, "x": 770, "y": 500, "wires": [ [ "967a8991.a09208" ] ] }, { "id": "967a8991.a09208", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例3: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 930, "y": 500, "wires": [] }, { "id": "332b2da9.4bc242", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join message sequence filtered by switch node", "info": "", "x": 260, "y": 440, "wires": [] }, { "id": "bbc984d8.be42d8", "type": "switch", "z": "7c9d326a56fe84a8", "name": "", "property": "payload.price", "propertyType": "msg", "rules": [ { "t": "gte", "v": "100", "vt": "num" } ], "checkall": "true", "repair": true, "outputs": 1, "x": 630, "y": 500, "wires": [ [ "716ea12e.1edb6" ] ] }, { "id": "6ff91f94.438e2", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into message sequence", "info": "", "x": 610, "y": 220, "wires": [] }, { "id": "9de138c7.480f08", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ automatically join message sequence using parts property", "info": "", "x": 800, "y": 140, "wires": [] }, { "id": "f06b21f.1d748e", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ automatically join message sequence using parts property", "info": "", "x": 800, "y": 300, "wires": [] }, { "id": "e0075028.900bb", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input csv data into message sequence of rows", "info": "", "x": 640, "y": 380, "wires": [] }, { "id": "1a390528.cf792b", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input csv data into message sequence of rows", "info": "", "x": 640, "y": 580, "wires": [] }, { "id": "eb05ee61.9e266", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ automatically join message sequence using parts property", "info": "", "x": 940, "y": 460, "wires": [] }, { "id": "33575fc6.e9b07", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ filter message seuqnce and create new sequence", "info": "", "x": 770, "y": 540, "wires": [] }, { "id": "7bf47d74.b233b4", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Example: Manual Mode", "info": "Join node can be used to join payload of messages into single message payload. In manual mode, it can uses number of messages, duration of time, or `msg.complete` property to decide sequence of messages to join. The data format of the join result can also be selected.", "x": 140, "y": 680, "wires": [] }, { "id": "7f104f68.aecff", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例4: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 800, "wires": [ [ "ed0381d3.e25fc" ] ] }, { "id": "ed0381d3.e25fc", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 800, "wires": [ [ "12b322b7.78f48d" ] ] }, { "id": "a4f5546e.28b268", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 630, "y": 800, "wires": [ [ "e3e636ab.5c5068" ] ] }, { "id": "12b322b7.78f48d", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 800, "wires": [ [ "a4f5546e.28b268" ] ] }, { "id": "e3e636ab.5c5068", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例4: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 800, "wires": [] }, { "id": "6a104137.204b3", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join two consecutive messages into single message", "info": "", "x": 270, "y": 740, "wires": [] }, { "id": "d91412a1.eb2fa", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 840, "wires": [] }, { "id": "db100cd0.4cfdd", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually join message sequence by ','", "info": "", "x": 740, "y": 760, "wires": [] }, { "id": "d873311b.ab6f8", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例5: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 960, "wires": [ [ "854ae07c.1b88f" ] ] }, { "id": "854ae07c.1b88f", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 960, "wires": [ [ "4da6db2a.a610f4" ] ] }, { "id": "5c158c02.fcd224", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "2", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 790, "y": 960, "wires": [ [ "659414e8.e901fc" ] ] }, { "id": "4da6db2a.a610f4", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 960, "wires": [ [ "8e4f1c67.cdac4" ] ] }, { "id": "659414e8.e901fc", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例5: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 950, "y": 960, "wires": [] }, { "id": "c002f9d0.a04128", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join messages received within specified time range into single message", "info": "", "x": 330, "y": 900, "wires": [] }, { "id": "3b62f93e.ad2af6", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 1000, "wires": [] }, { "id": "db741240.4d6a1", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually join message received withn 2 secs", "info": "", "x": 920, "y": 920, "wires": [] }, { "id": "8e4f1c67.cdac4", "type": "delay", "z": "7c9d326a56fe84a8", "name": "", "pauseType": "rate", "timeout": "1", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 650, "y": 960, "wires": [ [ "5c158c02.fcd224" ] ] }, { "id": "53363c0f.836454", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例6: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 1140, "wires": [ [ "33d9801f.5edc6" ] ] }, { "id": "33d9801f.5edc6", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 1140, "wires": [ [ "46fb1122.a49b" ] ] }, { "id": "e5d7310a.8ba39", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 850, "y": 1140, "wires": [ [ "d1a98ee5.3a55" ] ] }, { "id": "46fb1122.a49b", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 1140, "wires": [ [ "f32b7544.10b328" ] ] }, { "id": "d1a98ee5.3a55", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例6: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 1010, "y": 1140, "wires": [] }, { "id": "48f547c0.063278", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join messages into single message using msg.complete", "info": "", "x": 290, "y": 1060, "wires": [] }, { "id": "8106b831.3374e8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 1180, "wires": [] }, { "id": "373877fe.60a0d8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually join message sequence by msg.complete", "info": "", "x": 1000, "y": 1100, "wires": [] }, { "id": "f32b7544.10b328", "type": "function", "z": "7c9d326a56fe84a8", "name": "set msg.complete", "func": "var payload = msg.payload;\nif ((payload === \"Banana\") || (payload === \"Kiwi\")) {\n msg.complete = true;\n}\nreturn msg;", "outputs": 1, "noerr": 0, "x": 670, "y": 1140, "wires": [ [ "e5d7310a.8ba39" ] ] }, { "id": "90140dad.9cbd9", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ set msg.complete for Banana and Kiwi", "info": "", "x": 740, "y": 1060, "wires": [] }, { "id": "ead0afb6.a4763", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例7: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 1300, "wires": [ [ "175c6d3f.b71893" ] ] }, { "id": "175c6d3f.b71893", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 1300, "wires": [ [ "3a873d4a.fcc3a2" ] ] }, { "id": "88c0baeb.0f4c88", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "array", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 630, "y": 1300, "wires": [ [ "758b3990.2442c8" ] ] }, { "id": "3a873d4a.fcc3a2", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 1300, "wires": [ [ "88c0baeb.0f4c88" ] ] }, { "id": "758b3990.2442c8", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例7: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 1300, "wires": [] }, { "id": "9b1551a8.97d09", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Join two consecutive messages into single message of array", "info": "", "x": 300, "y": 1240, "wires": [] }, { "id": "655d7318.217b3c", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 1340, "wires": [] }, { "id": "66cdfd.5cba2204", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually join message sequence to array", "info": "", "x": 740, "y": 1260, "wires": [] }, { "id": "be206cc6.f8141", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例8: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 1520, "wires": [ [ "af8f52e6.e3d2f" ] ] }, { "id": "af8f52e6.e3d2f", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "name,price\nApple,100\nOrange,20\nBanana,80\nKiwi,120", "output": "str", "x": 350, "y": 1520, "wires": [ [ "89a32ebe.a92f1" ] ] }, { "id": "681800f4.06545", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "object", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 830, "y": 1520, "wires": [ [ "8442c86.2559838" ] ] }, { "id": "8442c86.2559838", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例8: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 990, "y": 1520, "wires": [] }, { "id": "d15e01f7.d0a1f", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Merge two consecutive messages into single message of object using topic & payload ", "info": "", "x": 380, "y": 1400, "wires": [] }, { "id": "cccc022b.dfbbc", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input csv data into messages", "info": "", "x": 580, "y": 1560, "wires": [] }, { "id": "65aef8f1.143ca8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually join message sequence to object", "info": "", "x": 950, "y": 1480, "wires": [] }, { "id": "89a32ebe.a92f1", "type": "csv", "z": "7c9d326a56fe84a8", "name": "", "sep": ",", "hdrin": true, "hdrout": "", "multi": "one", "ret": "\\n", "temp": "", "skip": "0", "strings": true, "include_empty_strings": "", "include_null_values": "", "x": 480, "y": 1520, "wires": [ [ "39fd09fc.b87e66" ] ] }, { "id": "39fd09fc.b87e66", "type": "change", "z": "7c9d326a56fe84a8", "name": "set topic & payload", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "payload.name", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload.price", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 650, "y": 1520, "wires": [ [ "681800f4.06545" ] ] }, { "id": "3fe71363.c5c67c", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ set topic (key) & payload (value)", "info": "", "x": 690, "y": 1440, "wires": [] }, { "id": "3f482b62.8ec0f4", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例9: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 1700, "wires": [ [ "63acc875.0d1458" ] ] }, { "id": "63acc875.0d1458", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "json", "syntax": "plain", "template": "[\n { \"name\": \"Apple\" },\n { \"price\": 100 },\n { \"name\": \"Orange\"},\n { \"price\": 20 },\n { \"name\": \"Banana\"},\n { \"price\": 80 },\n { \"name\": \"Kiwi\"},\n { \"price\": 120 }\n]", "output": "json", "x": 350, "y": 1700, "wires": [ [ "71aa03f2.69c42c" ] ] }, { "id": "82b9afbd.380bd", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "merged", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 630, "y": 1700, "wires": [ [ "df61f87d.0a7c38" ] ] }, { "id": "df61f87d.0a7c38", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例9: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 1700, "wires": [] }, { "id": "cff7cd24.8f70a", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Merge two consecutive messages into single message of object", "info": "", "x": 310, "y": 1620, "wires": [] }, { "id": "c8b4d7b0.7d2048", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split array of objects data into messages", "info": "", "x": 600, "y": 1740, "wires": [] }, { "id": "5f07dcb1.2a8384", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually merge message sequence to object", "info": "", "x": 760, "y": 1660, "wires": [] }, { "id": "71aa03f2.69c42c", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 1700, "wires": [ [ "82b9afbd.380bd" ] ] }, { "id": "dcbdbc0e.44c81", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例10: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 1880, "wires": [ [ "df188870.193ec8" ] ] }, { "id": "df188870.193ec8", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "json", "syntax": "plain", "template": "[\n { \"name\": \"Apple\" },\n { \"price\": 100 },\n { \"order\": 5 },\n { \"order\": 1 },\n { \"order\": 20 }\n]", "output": "json", "x": 350, "y": 1880, "wires": [ [ "61df0de9.80aaa4" ] ] }, { "id": "77072ce9.cd2ba4", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "custom", "build": "merged", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": true, "timeout": "", "count": "3", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 630, "y": 1880, "wires": [ [ "de78c2ec.efec3" ] ] }, { "id": "de78c2ec.efec3", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例10: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 1880, "wires": [] }, { "id": "f2b6aab7.9f69c8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Merge two consecutive messages and following messages into single message of object", "info": "", "x": 390, "y": 1800, "wires": [] }, { "id": "bf058927.d8e8b8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split array of objects data into messages", "info": "", "x": 600, "y": 1920, "wires": [] }, { "id": "2aab8acf.0673c6", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ manually merge message sequence to object", "info": "", "x": 760, "y": 1840, "wires": [] }, { "id": "61df0de9.80aaa4", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 1880, "wires": [ [ "77072ce9.cd2ba4" ] ] }, { "id": "9279b993.ba7ed8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Example: Reduce Mode", "info": "Join node can be used to reduce message sequence to single value. In reduce mode, reduce operation for a sequence can be described using JSONata expression with following special variables:\n- `$A`: the accumulated value,\n- `$I`: index of the message in the sequence,\n- `$N`: number of messages in the sequence.\n", "x": 150, "y": 2020, "wires": [] }, { "id": "e415861b.d82e38", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例11: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 2140, "wires": [ [ "7c8a4816.500ed8" ] ] }, { "id": "7c8a4816.500ed8", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "json", "syntax": "plain", "template": "[\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10\n]", "output": "json", "x": 350, "y": 2140, "wires": [ [ "7f64da1f.611014" ] ] }, { "id": "5fde318f.23897", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "reduce", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "$A+payload", "reduceInit": "0", "reduceInitType": "num", "reduceFixup": "$A/$N", "x": 630, "y": 2140, "wires": [ [ "50977eaf.0490b" ] ] }, { "id": "50977eaf.0490b", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例11: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 2140, "wires": [] }, { "id": "57bce4bf.38d02c", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Calculate average of message sequence", "info": "", "x": 240, "y": 2080, "wires": [] }, { "id": "d33e73a8.5896", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input array data into messages", "info": "", "x": 590, "y": 2180, "wires": [] }, { "id": "34482f62.61abd", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ reduce sequence to average value", "info": "", "x": 720, "y": 2100, "wires": [] }, { "id": "7f64da1f.611014", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 2140, "wires": [ [ "5fde318f.23897" ] ] }, { "id": "e051fd76.1af1e", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例12: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 2300, "wires": [ [ "14318520.397a9b" ] ] }, { "id": "14318520.397a9b", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 2300, "wires": [ [ "41d85177.9b6f1" ] ] }, { "id": "8fac92f8.0974c", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "reduce", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "$append($A,[payload])", "reduceInit": "[]", "reduceInitType": "json", "reduceFixup": "", "x": 630, "y": 2300, "wires": [ [ "5bf98f81.6db17" ] ] }, { "id": "5bf98f81.6db17", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例12: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 2300, "wires": [] }, { "id": "7dc61153.a9062", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Convert message sequence to array", "info": "", "x": 220, "y": 2240, "wires": [] }, { "id": "7f14c8b2.d775f8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 2340, "wires": [] }, { "id": "85a2470f.5b9ce8", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ reduce sequence to arrray of payloads", "info": "", "x": 740, "y": 2260, "wires": [] }, { "id": "41d85177.9b6f1", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 2300, "wires": [ [ "8fac92f8.0974c" ] ] }, { "id": "ec455af2.e31cb8", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例13: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 2460, "wires": [ [ "693a0274.e62d6c" ] ] }, { "id": "693a0274.e62d6c", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 2460, "wires": [ [ "d8374d2d.34863" ] ] }, { "id": "805c900a.c6b7c", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "reduce", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": true, "reduceExp": "$append($A,[payload])", "reduceInit": "[]", "reduceInitType": "json", "reduceFixup": "", "x": 630, "y": 2460, "wires": [ [ "f8be3623.b8e358" ] ] }, { "id": "f8be3623.b8e358", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例13: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 2460, "wires": [] }, { "id": "88fe5fe0.b08ca", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Convert message sequence to array in reverse order", "info": "", "x": 270, "y": 2400, "wires": [] }, { "id": "f95fff12.45fda", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 2500, "wires": [] }, { "id": "b7eecb8c.e6b858", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ reduce sequence to arrray of payloads in reverse order", "info": "", "x": 790, "y": 2420, "wires": [] }, { "id": "d8374d2d.34863", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 2460, "wires": [ [ "805c900a.c6b7c" ] ] }, { "id": "fb404773.0eb728", "type": "inject", "z": "7c9d326a56fe84a8", "name": "例14: 実行", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 200, "y": 2620, "wires": [ [ "8139dcd5.2300d" ] ] }, { "id": "8139dcd5.2300d", "type": "template", "z": "7c9d326a56fe84a8", "name": "data", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "Apple\nOrange\nBanana\nKiwi", "output": "str", "x": 350, "y": 2620, "wires": [ [ "c6ff515e.f95fd" ] ] }, { "id": "fcff950d.0f67c8", "type": "join", "z": "7c9d326a56fe84a8", "name": "", "mode": "reduce", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "accumulate": false, "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "$append($A,[{\t \"name\": payload,\t \"index\": $I\t}])", "reduceInit": "[]", "reduceInitType": "json", "reduceFixup": "", "x": 630, "y": 2620, "wires": [ [ "6d082a22.2fb214" ] ] }, { "id": "6d082a22.2fb214", "type": "debug", "z": "7c9d326a56fe84a8", "name": "例14: 結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 790, "y": 2620, "wires": [] }, { "id": "19daaf11.40d701", "type": "comment", "z": "7c9d326a56fe84a8", "name": "Convert message sequence to array of objects with name and index", "info": "", "x": 320, "y": 2560, "wires": [] }, { "id": "b60f900.592e47", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↑ split input text data into messages", "info": "", "x": 580, "y": 2660, "wires": [] }, { "id": "62ffb2e1.28d8ec", "type": "comment", "z": "7c9d326a56fe84a8", "name": "↓ reduce sequence to arrray of objects", "info": "", "x": 730, "y": 2580, "wires": [] }, { "id": "c6ff515e.f95fd", "type": "split", "z": "7c9d326a56fe84a8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 490, "y": 2620, "wires": [ [ "fcff950d.0f67c8" ] ] } ]

フローの読み解き

フローには、公式サンプルの14の例が、上から順に並んでいます。「Example:」で始まる comment ノードが3つあり、その下に、join ノードの「動作」ごとの例がまとまっています。どの例も、「例N: 実行」(inject)のボタンで動かし、「例N: 結果」(debug)に結果が出ます。inject が送る値(時刻)は使われません。つなぐ元のデータは、次の「data」(template)に書いてあります。

どの例も、データをいったん1個ずつの msg に分け、join でまとめ直す作りです。分けるのは split(文字列を行ごとに、配列を要素ごとに分ける)か、csv(CSV の文字を行ごとに分ける)です。各例の上下にある「↓」「↑」付きの comment は、その下・上のノードが何をしているかの説明です。

Example: Automatic Mode(自動。例1〜3): join は、split や csv が各 msg に付けた列の印(msg.parts)を見て、同じ列の msg がすべて届いたところで、元の形にまとめます。設定は「動作」を「自動」にするだけです。

例 comment ノードの見出し(意味) ノードの並びと、join の設定 「例N: 結果」に出るもの パターン
例1 Join message sequence created by split node(split ノードが作ったメッセージ列をつなぐ) 「例1: 実行」→「data」(template。4行の文字)→ split → join →「例1: 結果」。join は「動作」が「自動」 元と同じ4行の文字列(Apple、Orange、Banana、Kiwi が改行でつながったもの) パターン1
例2 Join message sequence created by csv node(csv ノードが作ったメッセージ列をつなぐ) 「例2: 実行」→「data」(template。CSV の文字)→ csv → join →「例2: 結果」。csv ノードが、行ごとに1つの msg を出す [{"name":"Apple","price":100},{"name":"Orange","price":80},{"name":"Banana","price":120},{"name":"Kiwi","price":50}](4行分のオブジェクトの配列) ―
例3 Join message sequence filtered by switch node(switch ノードで絞り込んだメッセージ列をつなぐ) 例2の csv と join の間に switch がある。switch は price が 100 以上のものだけを通し、「メッセージ列の補正」がオン [{"name":"Apple","price":100},{"name":"Banana","price":120}](条件に合った2行だけ) ―

Example: Manual Mode(手動。例4〜10): いくつ(または、いつまで)の msg をまとめるか、まとめた結果をどの形にするかを、join の設定で決めます。

例 comment ノードの見出し(意味) ノードの並びと、join の設定 「例N: 結果」に出るもの パターン
例4 Join two consecutive messages into single message(続けて届いた2つの msg を、1つの msg にまとめる) 「例4: 実行」→「data」→ split → join →「例4: 結果」。join は「動作」が「手動」、「出力」が「文字列」、「連結文字」が ,、「指定数のメッセージパーツを受信後」が 2 Apple,Orange、Banana,Kiwi の2つ パターン2
例5 Join messages received within specified time range into single message(決めた時間のあいだに届いた msg を、1つにまとめる) 例4の split と join の間に delay(1秒に1メッセージ)がある。join は「最初のメッセージ受信からのタイムアウト後」が 2 秒 約2秒ごとに、Apple,Orange、Banana,Kiwi パターン3
例6 Join messages into single message using msg.complete(msg.complete を使って、msg を1つにまとめる) split と join の間に「set msg.complete」(function)がある。Banana と Kiwi の msg に msg.complete を付ける。join は、個数も時間も指定していない Apple,Orange,Banana、Kiwi の2つ。msg.complete の付いた msg が届いたところで、そこまでをまとめて出す ―
例7 Join two consecutive messages into single message of array(続けて届いた2つの msg を、配列の msg にまとめる) 例4と同じ並び。join の「出力」が「配列」 ["Apple","Orange"]、["Banana","Kiwi"] の2つ パターン4
例8 Merge two consecutive messages into single message of object using topic & payload(続けて届いた2つの msg を、topic と payload を使ってオブジェクトにまとめる) 「例8: 実行」→「data」(CSV)→ csv →「set topic & payload」(change)→ join →「例8: 結果」。change が、msg.topic に名前、msg.payload に値段を入れる。join の「出力」は「key/valueオブジェクト」で、msg.topic をキーにする {"Apple":100,"Orange":20}、{"Banana":80,"Kiwi":120} の2つ パターン5
例9 Merge two consecutive messages into single message of object(続けて届いた2つの msg を、1つのオブジェクトに合わせる) 「data」(template。オブジェクト8個の配列)→ split → join。join の「出力」は「結合オブジェクト」で、2つのオブジェクトのプロパティを1つに合わせる {"name":"Apple","price":100}、{"name":"Orange","price":20}、{"name":"Banana","price":80}、{"name":"Kiwi","price":120} の4つ ―
例10 Merge two consecutive messages and following messages into single message of object(最初の msg と、そのあとに続く msg を、1つのオブジェクトに合わせる) 例9と同じ並び。join は「指定数のメッセージパーツを受信後」が 3 で、「後続のメッセージ毎」がオン {"name":"Apple","price":100,"order":5}、続いて "order":1、"order":20 に変わったものが1つずつ(計3つ)。3つそろったあとは、msg が届くたびに、それまでの内容に上書きして出す ―

Example: Reduce Mode(列の集約。例11〜14): 列の msg を1つずつ式で処理して、1つの値にまとめます。式は JSONata で書き、$A(それまでの結果)、$I(列の中の番号。0 から)、$N(列の msg の数)を使えます。

例 comment ノードの見出し(意味) ノードの並びと、join の設定 「例N: 結果」に出るもの パターン
例11 Calculate average of message sequence(メッセージ列の平均を求める) 「例11: 実行」→「data」(1〜10 の配列)→ split → join →「例11: 結果」。join は「動作」が「列の集約」、「集約式」が $A+payload、「初期値」が数値の 0、「最終調整式」が $A/$N 5.5(1〜10 を足した 55 を、個数の 10 で割った値) パターン6
例12 Convert message sequence to array(メッセージ列を配列にする) 「data」(4行の文字)→ split → join。「集約式」が $append($A,[payload])、「初期値」が空の配列 [] ["Apple","Orange","Banana","Kiwi"] ―
例13 Convert message sequence to array in reverse order(メッセージ列を、逆の順番の配列にする) 例12と同じ設定で、「評価を逆順に行う (最後から最初)」がオン ["Kiwi","Banana","Orange","Apple"] ―
例14 Convert message sequence to array of objects with name and index(メッセージ列を、名前と番号を持つオブジェクトの配列にする) 例12の「集約式」を、payload と $I(列の中の番号)からオブジェクトを作る式にしたもの [{"name":"Apple","index":0},{"name":"Orange","index":1},{"name":"Banana","index":2},{"name":"Kiwi","index":3}] ―

パターン1: 自動モード(Splitと連携)

用途: Splitノードで分割したメッセージを元の形式に再結合(サンプルフローの例1)

Inject → Template → Split →→→ Join
(自動)
→ Debug

動作の流れ:

  1. "Apple\nOrange\nBanana\nKiwi" をSplitで分割
  2. 4つの個別メッセージが順番に送信される
  3. JoinがSplitが付与したmsg.partsを使って自動再結合
  4. 元の形式に戻る

設定例:

動作: 自動 入力: "Apple" → "Orange" → "Banana" → "Kiwi" (4メッセージ) 出力: "Apple\nOrange\nBanana\nKiwi" (1メッセージ)

パターン2: 手動モード(メッセージ数指定)

用途: 指定した数のメッセージを結合(サンプルフローの例4)

Inject → Split →→→ Join
(count=2)
→→ Debug

動作の流れ:

  1. 4つのメッセージ "Apple", "Orange", "Banana", "Kiwi" を受信
  2. 2つずつ結合して出力
  3. "Apple,Orange" → "Banana,Kiwi" の2つのメッセージが出力

設定例:

動作: 手動 出力: 文字列 連結文字: , 指定数のメッセージパーツを受信後: 2 入力: "Apple" → "Orange" → "Banana" → "Kiwi" 出力: "Apple,Orange" → "Banana,Kiwi"

パターン3: 手動モード(タイムアウト指定)

用途: 指定時間内のメッセージを結合(サンプルフローの例5)

Inject → Split →→→ Delay
(1秒/msg)
→→→ Join
(2秒)
→ Debug

動作の流れ:

  1. メッセージを1秒間隔で受信
  2. 2秒のタイムアウトで結合
  3. 2秒以内に届いたメッセージをまとめて出力

設定例:

動作: 手動 出力: 文字列 連結文字: , 最初のメッセージ受信からのタイムアウト後: 2(秒) 入力: 1秒間隔で "Apple" → "Orange" → "Banana" → "Kiwi" 出力: "Apple,Orange" → "Banana,Kiwi" (約2秒ごとに出力)

パターン4: 配列形式での結合

用途: 複数メッセージの配列への結合(サンプルフローの例7)

Inject → Split →→→ Join
(配列)
→ Debug

設定例:

動作: 手動 出力: 配列 指定数のメッセージパーツを受信後: 2 入力: "Apple" → "Orange" → "Banana" → "Kiwi" 出力: ["Apple", "Orange"] → ["Banana", "Kiwi"]

パターン5: オブジェクト形式での結合

用途: msg.topicをキーとしたオブジェクトを作成(サンプルフローの例8)

Inject → Template
(CSV)
→ CSV →→→ Change
(topic設定)
→→→ Join
(オブジェクト)
→ Debug

動作の流れ:

  1. TemplateノードでCSVの文字データを作成
  2. CSVノードで、行ごとの個別のメッセージに分割
  3. Changeノードでmsg.topicに商品名、msg.payloadに価格を設定
  4. Joinでtopicをキー、payloadを値としたオブジェクトに結合

設定例:

動作: 手動 出力: key/valueオブジェクト 指定数のメッセージパーツを受信後: 2 入力: {topic: "Apple", payload: 100} → {topic: "Orange", payload: 20} 出力: {"Apple": 100, "Orange": 20}

パターン6: Reduceモード(平均値計算)

用途: メッセージシーケンスを集計して単一の値に(サンプルフローの例11)

Inject → Template
([1-10])
→ Split →→→ Join
(Reduce)
→ Debug

Reduceの特殊変数:

設定例:

動作: 列の集約(Reduce) 集約式: $A + payload 初期値: 0 最終調整式: $A / $N 入力: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 処理: (1+2+3+4+5+6+7+8+9+10) / 10 出力: 5.5 (平均値)

4. 実践演習

演習1: 文字列の結合初級

課題:

カンマ区切りの都市名を分割し、「/」で再結合してください。

💼 使いどころ: カンマ区切りのデータを、スラッシュなど別の区切り文字を使う形式に変換する場面で使います。

要求仕様:

期待される動作:

成功の条件:

💡 ヒント

Injectノードの設定:

  • payload: 文字列型で "東京,大阪,名古屋,福岡"

Splitノードの設定:

  • 分割方法: 文字列
  • 区切り文字: ,

Joinノードの設定:

  • 動作: 手動
  • 出力: 文字列
  • 連結文字: /
  • 指定数のメッセージパーツを受信後: 4(または msg.parts.count を使う自動モードでも可)
✅ 解答例フロー
[ { "id": "join_node_guide_tab_1", "type": "tab", "label": "join_node_guide 例2", "disabled": false, "info": "", "env": [] }, { "id": "ex1_inject", "type": "inject", "z": "join_node_guide_tab_1", "name": "都市名入力", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "東京,大阪,名古屋,福岡", "payloadType": "str", "x": 130, "y": 100, "wires": [ [ "ex1_split" ] ] }, { "id": "ex1_split", "type": "split", "z": "join_node_guide_tab_1", "name": "カンマ分割", "splt": ",", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "property": "payload", "x": 300, "y": 100, "wires": [ [ "ex1_join" ] ] }, { "id": "ex1_join", "type": "join", "z": "join_node_guide_tab_1", "name": "スラッシュ結合", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "/", "joinerType": "str", "useparts": false, "accumulate": "false", "timeout": "", "count": "4", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 480, "y": 100, "wires": [ [ "ex1_debug" ] ] }, { "id": "ex1_debug", "type": "debug", "z": "join_node_guide_tab_1", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 650, "y": 100, "wires": [] } ]

演習2: 配列への変換中級

課題:

改行区切りのテキストを分割し、配列に変換してください。

💼 使いどころ: 改行区切りのテキストを配列に変換し、後続のノードで一覧として扱えるようにする場面で使います。

要求仕様:

期待される動作:

成功の条件:

💡 ヒント

Templateノードの設定:

  • テンプレート: りんご、みかん、バナナを改行で区切って入力
  • 出力: 文字列

Splitノードの設定:

  • 分割方法: 文字列
  • 区切り文字: \n(改行)

Joinノードの設定:

  • 動作: 手動
  • 出力: 配列
  • 指定数のメッセージパーツを受信後: 3
✅ 解答例フロー
[ { "id": "join_node_guide_tab_2", "type": "tab", "label": "join_node_guide 例3", "disabled": false, "info": "", "env": [] }, { "id": "ex2_inject", "type": "inject", "z": "join_node_guide_tab_2", "name": "実行", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 110, "y": 100, "wires": [ [ "ex2_template" ] ] }, { "id": "ex2_template", "type": "template", "z": "join_node_guide_tab_2", "name": "フルーツリスト", "field": "payload", "fieldType": "msg", "format": "text", "syntax": "plain", "template": "りんご\nみかん\nバナナ", "output": "str", "x": 260, "y": 100, "wires": [ [ "ex2_split" ] ] }, { "id": "ex2_split", "type": "split", "z": "join_node_guide_tab_2", "name": "改行分割", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "property": "payload", "x": 420, "y": 100, "wires": [ [ "ex2_join" ] ] }, { "id": "ex2_join", "type": "join", "z": "join_node_guide_tab_2", "name": "配列に結合", "mode": "custom", "build": "array", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "useparts": false, "accumulate": "false", "timeout": "", "count": "3", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 580, "y": 100, "wires": [ [ "ex2_debug" ] ] }, { "id": "ex2_debug", "type": "debug", "z": "join_node_guide_tab_2", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 730, "y": 100, "wires": [] } ]

演習3: オブジェクトの作成中級

課題:

商品と価格のペアからオブジェクトを作成してください。

💼 使いどころ: 複数の商品データを、商品名から価格をすぐ調べられる一覧に整理する場面で使います。

要求仕様:

期待される動作:

成功の条件:

💡 ヒント

Templateノードの設定:

  • 形式: JSON
  • テンプレート: [{"name": "Apple", "price": 150}, {"name": "Orange", "price": 80}]
  • 出力形式: パース済みJSONオブジェクト(配列として出力される)

Splitノードの設定:

  • 配列は自動認識されるのでデフォルト設定でOK

Changeノードの設定:

  • msg.topic を msg.payload.name に設定
  • msg.payload を msg.payload.price に設定

Joinノードの設定:

  • 動作: 手動
  • 出力: key/valueオブジェクト
  • 指定数のメッセージパーツを受信後: 2
✅ 解答例フロー
[ { "id": "join_node_guide_tab_3", "type": "tab", "label": "join_node_guide 例4", "disabled": false, "info": "", "env": [] }, { "id": "ex3_inject", "type": "inject", "z": "join_node_guide_tab_3", "name": "実行", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 110, "y": 100, "wires": [ [ "ex3_template" ] ] }, { "id": "ex3_template", "type": "template", "z": "join_node_guide_tab_3", "name": "商品データ", "field": "payload", "fieldType": "msg", "format": "json", "syntax": "plain", "template": "[{\"name\": \"Apple\", \"price\": 150}, {\"name\": \"Orange\", \"price\": 80}]", "output": "json", "x": 260, "y": 100, "wires": [ [ "ex3_split" ] ] }, { "id": "ex3_split", "type": "split", "z": "join_node_guide_tab_3", "name": "分割", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "property": "payload", "x": 390, "y": 100, "wires": [ [ "ex3_change" ] ] }, { "id": "ex3_change", "type": "change", "z": "join_node_guide_tab_3", "name": "topic/payload設定", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "payload.name", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload.price", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 530, "y": 100, "wires": [ [ "ex3_join" ] ] }, { "id": "ex3_join", "type": "join", "z": "join_node_guide_tab_3", "name": "オブジェクト結合", "mode": "custom", "build": "object", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "useparts": false, "accumulate": "false", "timeout": "", "count": "2", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 700, "y": 100, "wires": [ [ "ex3_debug" ] ] }, { "id": "ex3_debug", "type": "debug", "z": "join_node_guide_tab_3", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 850, "y": 100, "wires": [] } ]

演習4: Reduceで合計値を計算上級

課題:

センサーデータの合計値を計算してください。

💼 使いどころ: 複数の数値データを合計して1つの値にまとめる場面で使います。

要求仕様:

期待される動作:

成功の条件:

💡 ヒント

Templateノードの設定:

  • 形式: JSON
  • テンプレート: [10, 25, 30, 15, 20]
  • 出力: JSONオブジェクト

Splitノードの設定:

  • 配列は自動認識されるのでデフォルト設定でOK

Joinノードの設定:

  • 動作: 列の集約(Reduce)
  • 集約式: $A + payload
  • 初期値: 0(数値型)
  • 最終調整式: 空(合計のみなので不要)
✅ 解答例フロー
[ { "id": "join_node_guide_tab_4", "type": "tab", "label": "join_node_guide 例5", "disabled": false, "info": "", "env": [] }, { "id": "ex4_inject", "type": "inject", "z": "join_node_guide_tab_4", "name": "実行", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 110, "y": 100, "wires": [ [ "ex4_template" ] ] }, { "id": "ex4_template", "type": "template", "z": "join_node_guide_tab_4", "name": "センサーデータ", "field": "payload", "fieldType": "msg", "format": "json", "syntax": "plain", "template": "[10, 25, 30, 15, 20]", "output": "json", "x": 270, "y": 100, "wires": [ [ "ex4_split" ] ] }, { "id": "ex4_split", "type": "split", "z": "join_node_guide_tab_4", "name": "分割", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "property": "payload", "x": 410, "y": 100, "wires": [ [ "ex4_join" ] ] }, { "id": "ex4_join", "type": "join", "z": "join_node_guide_tab_4", "name": "合計計算", "mode": "reduce", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": ",", "joinerType": "str", "useparts": false, "accumulate": "false", "timeout": "", "count": "", "reduceRight": false, "reduceExp": "$A + payload", "reduceInit": "0", "reduceInitType": "num", "reduceFixup": "", "x": 550, "y": 100, "wires": [ [ "ex4_debug" ] ] }, { "id": "ex4_debug", "type": "debug", "z": "join_node_guide_tab_4", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "x": 690, "y": 100, "wires": [] } ]

5. まとめ

Joinノードのポイント

よくある間違い

次のステップ

Joinノードを習得したら、以下のノードも学んでみましょう:

6. トラブルシューティング

よくある問題と解決方法

問題 原因 解決方法
結合されない メッセージ数が不足 count数の確認、またはタイムアウトを設定
自動モードが動作しない msg.partsが欠落 途中のノードでmsg.partsを保持する設定を確認
順序がバラバラ 非同期処理による順序変更 msg.parts.indexを使用、またはSortノードで並べ替え
Reduce結果が期待と違う JSONata式のエラー 式を単純化して動作確認、$A/$I/$Nの使い方を確認
タイムアウトで途中出力 メッセージ到着が遅い タイムアウト値を調整、またはcount指定に変更
異なるグループが混在 msg.parts.idが異なる Splitノードの設定を確認、または手動モードを使用

7. 実務での活用例

ケース1: 複数センサーデータの統合

温度センサー + 湿度センサー + 気圧センサー ↓ Joinノード(オブジェクト形式) ↓ { "temperature": 25.5, "humidity": 60, "pressure": 1013 } ↓ データベース保存 or ダッシュボード表示

ケース2: API並列呼び出しの結果統合

ユーザー情報API → 注文履歴API → Join(マージ)→ 統合レスポンス 在庫情報API → 出力: { "user": {...}, "orders": [...], "inventory": {...} }

ケース3: バッチ処理の集計

1時間分のログデータ(100件) ↓ Split(行ごとに分割) ↓ フィルタリング(エラーログのみ) ↓ Join(集約式: $A + 1, 初期値: 0) ↓ エラー件数: 15

ケース4: IoTデバイスからのデータ集約

工場の10台のデバイス ↓ 各デバイスから生産数を受信(タイムアウト: 5秒) ↓ Join(配列形式) ↓ [120, 115, 130, 125, 110, 128, 122, 118, 132, 126] ↓ 合計・平均計算 → レポート生成

8. Reduceモード詳細

JSONata特殊変数

変数 説明 使用例
$A 累積値(アキュムレータ) $A + payload(合計)
$I 現在のインデックス(0から) インデックス付きオブジェクト作成
$N メッセージ総数 $A / $N(平均)
payload 現在のメッセージのpayload 各メッセージの値を参照

集約式の例

// 合計 $A + payload // 最大値 payload > $A ? payload : $A // 配列に追加 $append($A, [payload]) // オブジェクト配列に変換 $append($A, [{"value": payload, "index": $I}]) // 条件付き加算 payload > 10 ? $A + payload : $A

9. 追加リソース


このガイドが役に立ちましたら、実際のプロジェクトで練習してみてください!
Joinノードはデータの統合や集計に役立ちます。

参照元:NodeREDエディター内サンプルフロー

🏠