How to obtain Items column name and value toghether

Hi, I know there are other topics like that, but my request is a bit different, and I didn’t find any solution with the other already online.

Describe the problem/error/question

Hello everyone, I have this input:

{
"email":
"[email protected]",
"id":
1496026,
"emailBlacklisted":
false,
"smsBlacklisted":
false,
"createdAt":
"2023-06-01T17:07:36.444+02:00",
"modifiedAt":
"2023-06-01T17:07:38.422+02:00",
"listIds":
[
26
],
"attributes":
{
},
"row_number":
4,
"Primary_Email":
"[email protected]",
"Additional_Email":
"[email protected]",
"Additional_Email2":
"",
"Additional_Email3":
""
}

So I am receiving x items like that with x number of Additional_EmailX columns.
I would like to make a HTTP request, and I need to add in the body the following values:
“Additional_Email” (so the name of the columns) and the value of the column if it’s present.

So basically in the HTTP request need to run once every items incoming and use as parameters the name of the columns and the respect values.

Please share your workflow

I’ve tried to use
{{ $json.keys()[0] }}
But not worked

Information on your n8n setup

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

Hey @Gabriele_Bracciali,

You lost me, So do you need to run the http request node once for each additional email?

hi @Jon , sorry for bad explaination.
Yes, actually the hTTP request need to run for each additional email

So if we were to use the example data you would only have one post but if we had…

{
  "Primary_Email": "[email protected]",
  "Additional_Email": "[email protected]", 
  "Additional_Email2": "[email protected]",
  "Additional_Email3": "[email protected]"
}

You would want 3 posts where Additional_Email will be [email protected] for the first post then [email protected] for the second and [email protected] for the third rather than say having Additional_Email an array that contains all of the possible values?

I just want to make sure I get this right before playing with the code node and getting an example together :slight_smile:

Yes, so from all the input I want to focus only with Primary_Email and all the Additional_EmailX
The output need to have 1 item for each Additional_EmailX plus the first Primary_Email

Okay, I’ve found this Javascript solution so far:

const item = items[0].json;

const keys = Object.keys(item);

const result = [];

keys.forEach((key) => {
  result.push({
    json: {
      column: key,
      value: item[key],
    },
  });
});

return result;

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.