Fetch nested data which is dynamic

Hi Everyone,

I have a node which is outputting data in this format:

I then have a node which selects the right item from this data. The issue I am having is that someitmes new items get added to this array, so the index of e.g,14 is no longer relevant to the item that I want to pull. It would now be 15. Is there anyway I can get around this? Each Item has an ID that is unique to it so if I can somehow say I only want the item which has X id that could work?

Screenshot 2021-09-24 at 10.27.23
Screenshot 2021-09-24 at 10.28.21

Hey @aziadlourad,

What you could do is use a function node to loop over the items and check the name or id to see if it is what you expect then return that object.

I have not played with the items node yet but there could be something in there as well.

Hi, thanks for the reply.

How would I go about doing that with the looping?

@harshil1712 i remember you helped me with something similar a while ago in another post. Can you think of any solution to this?

Hey @aziadlourad,

Here’s the example that might help (you will have to connect the Item Lists1 node to the node that returns the input)

{
  "nodes": [
    {
      "parameters": {
        "fieldToSplitOut": "options",
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "attributes",
        "options": {}
      },
      "name": "Item Lists1",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"id\"]}}",
              "value2": "70cbf3d3-969f-496d-a451-37e3369eb163"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Item Lists1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

This workflow is first returning the attributes from the data. Then using the IF node, we are checking for the specific attribute. The true output will return only that specific attribute. We are then using another Item Lists node to return the nested options. I hope this helps :slight_smile:

1 Like

Hi @harshil1712

Thanks for your help. i know have this data

I want to pull out the data from one of these items, depending on what the unique ID associated with it is. For example I want I want the data from the options array of the item with id “660264…”. How would I go about doing this?

You can repeat the same nodes. Check for the ID using the IF node, extract the options using the Item Lists node, and use another IF node to return the specific option.