Webhook to IF-node, rename after (or before)

Hey everyone :slight_smile:
I am pretty new to n8n - and also to the community.
So first a big thank you for that epic piece of software and also for everything that is written here - most answers I found here.

Yet, there is one issue I just dont get my head around.
When receiving JSON from a webhook that contains either “input_abc” or “input_xyz”, I can use the IF-node, to output the value that arrived…
With the Merge-node I than can forward the one that arrived.
But now I want to rename the input_xyz or input_abc to just input_final.
But the Aggregate-node needs the correct value, so I can not use something like input_* and it will recognize both fields. I also dont really know, how to explain better and maybe, there is even a much better workflow instead of using the IF node?
Here is also the Workflow - maybe someone has an idea, how I could solve that.

So, actually, when having the right input (abc or xyz), I dont want to have that name but just input_final or something. Hope I did not explain to confusing :smiley:

Thank you very much!
sant0s

  • n8n version: 1.33.1
  • Database : SQLite
  • Running n8n via:Docker
  • n8n EXECUTIONS_PROCESS setting: own
  • Operating system: Win 11, n8n on Ubuntu Hetzner

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

You can use an edit fields node to customize fields like that

Let me know if that helps

Good morning.
Thank you for your answer.

With a code node it would look like that, lets say I have input_to_process_ABC und input_to_process_XYZ

function processItems(items) {
    const results = [];
    items.forEach(item => {
        item.json.content.forEach(contentItem => {
            for (let key in contentItem) {
                if (key.startsWith('input_to_process_')) {
                    results.push({ "input_final": contentItem[key] });
                }
            }
        });
    });
    return results;
}
return processItems(items);

That would, depending on what I receive, always output input_final and I can use that in other nodes.
But that is what I would like to do with native nodes - IF possible of course.
The function works as it should, but yet, maybe I am just missing the edits node possibilities and dont understand, how to do that.

You have an example, how to achieve that withoud additional code?

Can you share an example webhook payload?

I think you may be over thinking what is needed. The aggregate node shouldn’t be needed there and i can’t think of why two if statements would be set up like that

If you share the data i’ll make an example for you and explain the proccess

1 Like

Hey liam, thank you for answering again!
Yes, I realized, that using two if nodes made absolutly no sense.
I already changed that.
Currently, my setup looks like that to than feed ChatGPT.
Probably its just total overkill or I dont need to seperate all the JSON input before.
But somehow I otherwise always get an error related to array, stringt etc - so I figured, I always have to build a string from everything and than I can feed it into ChatGPT.

A typical payload would look like that:

[
  {
    "headers": {
      "host": "mywebsite.io",
      "x-forwarded-scheme": "https",
      "x-forwarded-proto": "https",
      "x-forwarded-for": "172.18.0.1",
      "x-real-ip": "172.18.0.1",
      "content-length": "276",
      "content-type": "application/json"
    },
    "params": {},
    "query": {},
    "body": {
      "content": {
        "post_id": 1904,
        "parameters": {
          "properties": {
            "title": "Test",
            "description": "test",
            "repeater_highlights": [
              "test",
              "test",
              "test"
            ],
            "custom_instruction_presets": "ALL CAPS",
            "language": "English",
            "writing_style_presets": "Persuasive"
          }
        }
      }
    }
  }
]

It works, also when I use that to feed ChatGPT etc.
But yet, I think, its quite a mess and could be way more streamlined.
The challenge for me actually is, that I can have many different inputs - so it will never be the same.
But at one point I am always getting lost, organizing the seperated JSON structure back into a structure.

edit:
oh and the following snippet is now used instead of if:

function processItems(items) {
    const results = [];
    items.forEach(item => {
        item.json.content.forEach(contentItem => {
            for (let key in contentItem) {
                if (key.startsWith('custom_instruction_')) {
                    results.push({ "custom_instruction": contentItem[key] });
                }
            }
        });
    });
    return results;
}
return processItems(items);

That will actually do what I want - but thats what I was trying with the IF node and after that renaming it to just “custom_instruction”.

Where is the source of the data?
Can you make it so it’s more consistent?

I think you may be over thinking some stuff here.
All of the values in the payload you can just directly use in fields.
When the json is not always the same you can use any expression that is a one liner to get it figured out.

If the input different enough each time to justify this then I would say a separate parsing workflow would be needed. Can’t really help more than that without seeing examples of how it varies and why

2 Likes

Hey liam.
Sorry - I thought I already answered, was somehow in “draft” :slight_smile:

Just wanted to give a feedback, that your hint with the “one-liner” was super usefull.
I was not aware of that expression stuff. Also I did not understand first, that I can use the set node to only pull the key and give it a new name etc.
As you said, I absolutly overcomplicated the workfllow.
So actually from many nodes (like 30 or so ^^) I could go down to 5 nodes with the same and quicker result.

Thank you!

You’re welcome!

Glad to hear you got some stuff figured out

1 Like