Find data in an array

Hello everyone, everything good?
Here I am again lol
Come on, my current problem is the following…
I’m using an integration with Asana, pulling data manually through HTTP Request.
I have a field that always has the same ID (1204219176386539), however, it does not always return in the same position, (custom_fields), I would like to know if there is any way for me to filter this data, but not by “custom_fields” but by the value of ID that is inside it, so I could always get the value I need.
Below I will leave an example of a rotorno in JSON format to illustrate.

I need to get the value from “number_value”

[
  {
    "data": [
      {
        "gid": "1207268343606082",
        "completed_at": "2024-05-08T20:25:49.820Z",
        "custom_fields": [
          {
            "gid": "1203886989258425"
          },
          {
            "gid": "1203886927254432"
          },
          {
            "gid": "1204219176386539",
            "number_value": 3
          },
          {
            "gid": "1204220600403329"
          },
          {
            "gid": "1204238274508618"
          }
        ]
      },
      {
        "gid": "1207270360944781",
        "completed_at": "2024-05-08T18:05:56.600Z",
        "custom_fields": [
         {
            "gid": "1204219176386539",
            "number_value": 4
          },
          {
            "gid": "1203886989258423"
          },
          {
            "gid": "1203886927254439"
          },         
          {
            "gid": "1204220600403321"
          }
        ]
      },
    ]
  }
]

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:

Hey @Pedro_Malaquias

Try this with JMESPath

1 Like

This expression gave me a strange response…
I need the output value to be the value contained in custom_field[n] that has GID=1204219176386539, however, the output would like it to be the value “number_value:3” as shown in the print below

Come on, I actually need it when I receive the input like this:
[
{
“date”: [
{
“gid”: “1207268343606082”,
“completed_at”: “2024-05-08T20:25:49.820Z”,
“custom_fields”: [
{
“gid”: “1203886989258425”
},
{
“gid”: “1203886927254432”
},
{
“gid”: “1204219176386539”,
“number_value”: 3
},
{
“gid”: “1204220600403329”
},
{
“gid”: “1204238274508618”
}
]
},
{
“gid”: “1207270360944781”,
“completed_at”: “2024-05-08T18:05:56.600Z”,
“custom_fields”: [
{
“gid”: “1204219176386539”,
“number_value”: 4
},
{
“gid”: “1203886989258423”
},
{
“gid”: “1203886927254439”
},
{
“gid”: “1204220600403321”
}
]
},
]
}
]

the output looks like this:
[
{
“date”: [
{
“gid”: “1207268343606082”,
“completed_at”: “2024-05-08T20:25:49.820Z”,
“custom_fields”: [

{
“gid”: “1204219176386539”,
“number_value”: 3
}
]
},
{
“gid”: “1207270360944781”,
“completed_at”: “2024-05-08T18:05:56.600Z”,
“custom_fields”: [
{
“gid”: “1204219176386539”,
“number_value”: 4
}
]
}
]
}
]

Because after removing the fields that I don’t need, I will take the output and manipulate it within the database

hello @Pedro_Malaquias

You can do it with array filtering

1 Like

First I think I should remove the data “array”, to be able to do this interaction with the custom fields array, right?

This is my flow, I’m doing an integration with Asana to get tasks completed in the last 24 hours (I removed sensitive data)
it returns me:

[
  {
    "data": [
      {
        "gid": "1207267839503513",
        "assignee": {
          "gid": "1206844449630586",
          "resource_type": "user"
        },
        "completed_at": "2024-05-09T17:16:24.153Z",
        "custom_fields": [
          {
            "gid": "1203886927254435"
          },
          {
            "gid": "1204220600403328"
          },
          {
            "gid": "1203886989258428"
          },
          {
            "gid": "1203886990821111",
            "number_value": null
          },
          {
            "gid": "1204219176386539",
            "number_value": 1
          },
          {
            "gid": "1205771040510147",
            "number_value": null
          },
          {
            "gid": "1204238274508611"
          }
        ]
      },
      {
        "gid": "1207230780063146",
        "assignee": {
          "gid": "1206362073473212",
          "resource_type": "user"
        },
        "completed_at": "2024-05-09T16:57:45.681Z",
        "custom_fields": [
          {
            "gid": "1203886989258428"
          },
          {
            "gid": "1205771040510147",
            "number_value": null
          },
          {
            "gid": "1204220600403328"
          },
          {
            "gid": "1204219176386539",
            "number_value": 10
          },
          {
            "gid": "1203886927254435"
          },
          {
            "gid": "1204238274508611"
          },
          {
            "gid": "1207251090649455"
          }
        ]
      },
      {
        "gid": "1207268614002234",
        "assignee": {
          "gid": "1169940208997012",
          "resource_type": "user"
        },
        "completed_at": "2024-05-09T16:51:23.352Z",
        "custom_fields": [
          {
            "gid": "1203886989258428"
          },
          {
            "gid": "1203886927254435"
          },
          {
            "gid": "1204219176386539",
            "number_value": 2
          },
          {
            "gid": "1204220600403328"
          },
          {
            "gid": "1204238274508611"
          }
        ]
      },
      {
        "gid": "1207268343606086",
        "assignee": {
          "gid": "1206844636156795",
          "resource_type": "user"
        },
        "completed_at": "2024-05-08T20:25:49.820Z",
        "custom_fields": [
          {
            "gid": "1203886989258428"
          },
          {
            "gid": "1203886927254435"
          },
          {
            "gid": "1204219176386539",
            "number_value": 3
          },
          {
            "gid": "1204220600403328"
          },
          {
            "gid": "1204238274508611"
          }
        ]
      }
    ]
  }
]

My idea is to filter the data so that the post-filter result is something like this:

[
      {
        "gid": "1207268343606082",
        "completed_at": "2024-05-08T20:25:49.820Z",
        "custom_fields": [
         
          {
            "gid": "1204219176386539",
            "number_value": 3
          }
        ]
      },
      {
        "gid": "1207270360944781",
        "completed_at": "2024-05-08T18:05:56.600Z",
        "custom_fields": [
         {
            "gid": "1204219176386539",
            "number_value": 4
          }
        ]
      }
    ]

I couldn’t apply your solution, could you explain it better?
Then I would interact with each piece of data to insert it into my database, working with the values ​​that are necessary.

My code now:

That’s how you can achieve that

2 Likes

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