Fetching Nested Data

Hi Everyone!

I want to split the data points “name”,“attribute_id” and “id” into a table. How do I access it? i cant use the item lists node because it is not an array.

Here is the data:

[
  {
    "attributes": {
      "f018a5b7-be83-4d78-89d1-b20aae875f0f": null,
      "d4e1aef2-c628-478e-b005-04565c642656": null,
      "252d7cc4-6964-4183-b849-0d5c31a44380": null,
      "caccd831-b2ad-4e69-aa8a-c0fb9ce9e7f0": null,
      "706c536a-0ace-451f-8c54-607143da8d48": null,
      "38a442b5-d6f0-4bf5-b0d5-4d4b608be781": null,
      "1e577bae-7233-4383-a847-63dce2bb0814": null,
      "e3a2c432-f108-4e46-b544-a0befc1a0280": null,
      "92d51f40-11aa-4ed9-b56b-8b9ed2c134cf": null,
      "d3705e0d-c650-4f0a-b779-550448c90551": null,
      "bc4f8be6-66f2-4b15-bdde-45979e2cdf96": [ ],
      "92ade986-848c-4b07-b416-07b6898fd110": {
        "id": "07960ffb-57c2-4041-bf7a-084c9c45fcbf",
        "attribute_id": "92ade986-848c-4b07-b416-07b6898fd110",
        "name": "First Call"
      },
      "2d9f3f49-fb50-43ac-92e7-9db18c3d3e65": null,
      "286b7fec-89ff-4d3c-94ee-8ae0e6414dce": null,
      "eed33fd5-3212-4032-8abf-694f8073f4fe": null,
      "71248b99-6ad8-4573-8ea5-66906485972e": null,
      "c1b4cfb0-9983-4e94-9f55-6b4a896b3d7f": null,
      "e176210b-4116-4d08-a968-e85237ee738a": null,
      "f592ff6b-b60c-42f4-a756-b60e4d6e0a13": null,
      "6a5cdcca-5e95-4ebd-9566-1cfc5a0a06d2": null
    }
  }
]

Hi @aziadlourad, this could be a bit tricky but should be doable.

Will id, attribute_id, and name always be nested under the 92ade986-848c-4b07-b416-07b6898fd110 field inside the attributes field of your items? Or could these fields potentially appear under any of the other UUIDs?

1 Like

Hi, yes it will always be nested under that field area.

1 Like

Perfect! So in this case it’s not tricky at all and you should be able to use a simple Set node like so:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [{json:\n  {\n    \"attributes\": {\n      \"f018a5b7-be83-4d78-89d1-b20aae875f0f\": null,\n      \"d4e1aef2-c628-478e-b005-04565c642656\": null,\n      \"252d7cc4-6964-4183-b849-0d5c31a44380\": null,\n      \"caccd831-b2ad-4e69-aa8a-c0fb9ce9e7f0\": null,\n      \"706c536a-0ace-451f-8c54-607143da8d48\": null,\n      \"38a442b5-d6f0-4bf5-b0d5-4d4b608be781\": null,\n      \"1e577bae-7233-4383-a847-63dce2bb0814\": null,\n      \"e3a2c432-f108-4e46-b544-a0befc1a0280\": null,\n      \"92d51f40-11aa-4ed9-b56b-8b9ed2c134cf\": null,\n      \"d3705e0d-c650-4f0a-b779-550448c90551\": null,\n      \"bc4f8be6-66f2-4b15-bdde-45979e2cdf96\": [ ],\n      \"92ade986-848c-4b07-b416-07b6898fd110\": {\n        \"id\": \"07960ffb-57c2-4041-bf7a-084c9c45fcbf\",\n        \"attribute_id\": \"92ade986-848c-4b07-b416-07b6898fd110\",\n        \"name\": \"First Call\"\n      },\n      \"2d9f3f49-fb50-43ac-92e7-9db18c3d3e65\": null,\n      \"286b7fec-89ff-4d3c-94ee-8ae0e6414dce\": null,\n      \"eed33fd5-3212-4032-8abf-694f8073f4fe\": null,\n      \"71248b99-6ad8-4573-8ea5-66906485972e\": null,\n      \"c1b4cfb0-9983-4e94-9f55-6b4a896b3d7f\": null,\n      \"e176210b-4116-4d08-a968-e85237ee738a\": null,\n      \"f592ff6b-b60c-42f4-a756-b60e4d6e0a13\": null,\n      \"6a5cdcca-5e95-4ebd-9566-1cfc5a0a06d2\": null\n    }\n  }\n}]"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "id",
              "value": "={{$json[\"attributes\"][\"92ade986-848c-4b07-b416-07b6898fd110\"][\"id\"]}}"
            },
            {
              "name": "attribute_id",
              "value": "={{$json[\"attributes\"][\"92ade986-848c-4b07-b416-07b6898fd110\"][\"attribute_id\"]}}"
            },
            {
              "name": "name",
              "value": "={{$json[\"attributes\"][\"92ade986-848c-4b07-b416-07b6898fd110\"][\"name\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I have put together the expressions used here through the expression editor so I didn’t need to remember their syntax and could just click through a tree structure:

image

You can open the expression editor by clicking on the little gear icon next to each input field:

image

This will produce the following output:

If you don’t need the original attributes field you could enable the Keep Only Set option of the Set node. Hope this makes sense and helps!

1 Like