Search code examples
jsonnode-red

Joining two JSON objects in Node-RED


it's pretty simple. I have two flows in Node-RED, each of them carrying a JSON object.

As you can see here:

Overview Originally on the first path, I created a new JSON object using the Template Node, which then was passed to the next node. Which works just fine.

Now, I have two flows from which I want to extract data.

Problem: The Template node only takes one input at a time. The result is two separated new JSON objects.

But, my target case is this combined JSON object:

{
    "followupEventInput": {
        "name": "{{response.prevIntent}}-{{response.utterances_tone.0.tones.0.tone_id}}",
        "parameters": {
            "tone_id": "{{response.utterances_tone.0.tones.0.tone_id}}"
        },
        "languageCode": "en-US"
  }
}

response.utterances_tone.0.tones.0.tone_id coming from the first flow.

response.prevIntent coming from the second flow.

It's not possible to pass the information I need through the first flow, because the information gets lost when passing the Tone Analyzer node.

I tried to work with Split & Join nodes but it just gets messy.

Have you any idea how this could be implemented smoothly?


Solution

  • Have a look at the join node.

    This node has a number of modes, but you want the one that counts incoming messages before the outputting and object.

    This will output a message with all the fields available, but you will probably need to use a function or change node to rearrange the structure to the one you want.