How to remove an object and leave only the values?

I understand that need to use the function node? I do not know JavaScript, I ask for help. All objects have different key names, which are equal to “account_id”.

Hey @Roket,

The example below should do the work. You just have to use the node “function1”. The node called function it’s just to mockup the incoming data.

If you have any other questions let us know. We are happy to help.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n   {\n      json: {\n          '1': {\n            account_id: 123,\n            account_name: \"epale\",\n            remaining_account_budget: \"121212\",\n            percent_spend: \"99.57\",\n            daily_budget: \"12121\",\n            weekly_spend: \"asasasa\",\n            daily_spend: 123\n          },\n          '2': {\n            account_id: 123,\n            account_name: \"epale\",\n            remaining_account_budget: \"121212\",\n            percent_spend: \"99.57\",\n            daily_budget: \"12121\",\n            weekly_spend: \"asasasa\",\n            daily_spend: 123\n          }\n      },\n   },\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const result = []\nfor (const item of items) {\n  for (const key in item.json) {\n    result.push({\n      json: item.json[key]\n    })\n  }\n}\n\nreturn result"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        620,
        310
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks a lot!
It helps me!

How to make such a structure out of the resulting JSON?
{ “Action”: “Add”,
“Properties”: {
“Locale”: “ru-RU”,
“Location”: “00.000000, 00.000000”,
“Timezone”: “Pacific Standard Time”,
“RunAsUserEmail”: “[email protected]”},
“Rows”:
[
{This is the resulting JSON from RicardoE105}
]
}

@Roket this should do the work. Let me know if you have any other questions.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n   {\n      json: {\n          '1': {\n            account_id: 123,\n            account_name: \"epale\",\n            remaining_account_budget: \"121212\",\n            percent_spend: \"99.57\",\n            daily_budget: \"12121\",\n            weekly_spend: \"asasasa\",\n            daily_spend: 123\n          },\n          '2': {\n            account_id: 123,\n            account_name: \"epale\",\n            remaining_account_budget: \"121212\",\n            percent_spend: \"99.57\",\n            daily_budget: \"12121\",\n            weekly_spend: \"asasasa\",\n            daily_spend: 123\n          }\n      },\n   },\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        520,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const result = []\nfor (const item of items) {\n  for (const key in item.json) {\n    result.push({\n      json: item.json[key]\n    })\n  }\n}\n\nreturn result"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        310
      ]
    },
    {
      "parameters": {
        "functionCode": "const rows = []\n\nfor (const item of items) {\n  rows.push(item.json)\n}\n\n\nreturn [\n    {\n   json: {\n    Action: \"Add\",\n    Properties: {\n      Locale: \"ru-RU\",\n      Location: \"00.000000, 00.000000\",\n      Timezone: \"Pacific Standard Time\",\n      RunAsUserEmail: \"[email protected]\"\n    },\n    Rows: rows\n  }\n}\n]"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        310
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Everything works! Thank you very much! Sorry for the inexperience, I’m trying to switch from Zapier.) And the last question:

There was a positive experience in another workflow, but I was working with data from Webhook. And here with the JSON file I can’t understand how to transfer the resulting file to another service.

@Roket check the image below. I did not add the headers because I cannot get to see what you put there.

Keep in mind in my example the node where the data comes from is called “function2” for you this might be different depending on how you named that node.

Let me know if something.

1 Like

Did not work(

@Roket The only thing that comes to mind it’s you are not using the latest version of n8n. So instead of using JSON use data. The expression should be like this:

{{$node[“function21”].data}}

If that does not fix the issue simply get back to me.

Regards.

1 Like


How to update n8n?

@Roket do something for me. On the variable selector Open nodes --> function21 --> output data and take a picture.

1 Like

Everything works! Thanks again!
It was enough to make an Execute Node on the Function21 node.

@Roket Perfect. If you have any other further questions simply let’s us know.