Look up for a specific value in a list of items

Hey community,

First of all, this is my first message here. I wanted to say thank you. I have already found a lot of incredible help here, that helps me get better at using n8n. So thank you very much for that!

Here is my problem: I’d like to look up a specific “label” regarding its “id” that I get in the “value” field.

See below the data structure :

For this example, my intention is to set a new string called “vertical” that should be “Vente de leads” in this case because the “value” corresponds to its “id”.

Could you please help me writing the correct expression ? :pray:

Thank you very much,
Romain

1 Like

Hi @RomainMaltrud, welcome to the community :tada:

Glad to hear you enjoy using n8n so far!

Such a lookup inside an expression is a bit tricky I am afraid. It would require the use of JMESPath (or regular JavaScript code). Happy to help with your first expression though. Could you perhaps share the actual JSON data structure you are working with? The screenshot only shows a very small part of it.

You can copy it like so:

You can, of course, redact any confidential values you might have in there, just make sure to keep the data structure itself.

1 Like

Hey @MutedJam, thank you for your response and for providing me with some help with the first expression! It means a lot to me :slight_smile:

Here is the JSON data structure, I have bolded the field that are involved in the data I’m trying to set :slight_smile:

[
{
    "data": [
      {
        "value": null,
        "type": "simple-text",
        "parameters": {
          "default_value": null,
          "char_min": null,
          "char_max": null
        },
        "id": 170513,
        "name": "id paiement Stripe",
        "code": "idpaiementstripe",
        "description": "",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      },
      {
        "value": null,
        "type": "simple-text",
        "parameters": {
          "default_value": null,
          "char_min": null,
          "char_max": null
        },
        "id": 188047,
        "name": "FacturationUnitead",
        "code": "factunitead",
        "description": "Correspondance des numéros de factures dans la plateforme Unitead V3",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      },
      {
        "value": "https://app.unitead.fr/paiements-nc-64400baa40c80.html",
        "type": "simple-text",
        "parameters": {
          "default_value": null,
          "char_min": null,
          "char_max": null
        },
        "id": 188050,
        "name": "Stripe Payment URL",
        "code": "stripeurlpayment",
        "description": "",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      },
      {
        **"value": 3743318,**
        "type": "select",
        "parameters": {
          "items": [
            {
              **"id": 3743318,**
**              "label": "Vente de leads",**
              "checked": true,
              "rank": 0
            },
            {
              "id": 3743319,
              "label": "Vente de chantiers",
              "checked": false,
              "rank": 1
            },
            {
              "id": 3743320,
              "label": "Monétisation",
              "checked": false,
              "rank": 2
            },
            {
              "id": 3865882,
              "label": "Ulead",
              "checked": false,
              "rank": 3
            }
          ]
        },
        "id": 189034,
        "name": "Pôle d'activité",
        "code": "poleactivite",
        "description": "",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      },
      {
        "value": 3743327,
        "type": "select",
        "parameters": {
          "items": [
            {
              "id": 3743321,
              "label": "Octobre 2022",
              "checked": true,
              "rank": 5
            },
            {
              "id": 3743322,
              "label": "Novembre 2022",
              "checked": false,
              "rank": 6
            },
            {
              "id": 3743323,
              "label": "Décembre 2022",
              "checked": false,
              "rank": 7
            },
            {
              "id": 3743324,
              "label": "Janvier 2023",
              "checked": false,
              "rank": 8
            },
            {
              "id": 3743325,
              "label": "Février 2023",
              "checked": false,
              "rank": 9
            },
            {
              "id": 3743326,
              "label": "Mars 2023",
              "checked": false,
              "rank": 10
            },
            {
              "id": 3743327,
              "label": "Avril 2023",
              "checked": false,
              "rank": 11
            },
            {
              "id": 3743328,
              "label": "Mai 2023",
              "checked": false,
              "rank": 12
            },
            {
              "id": 3743329,
              "label": "Juin 2023",
              "checked": false,
              "rank": 13
            },
            {
              "id": 3743330,
              "label": "Juillet 2023",
              "checked": false,
              "rank": 14
            },
            {
              "id": 3743331,
              "label": "Août 2023",
              "checked": false,
              "rank": 15
            },
            {
              "id": 3743332,
              "label": "Septembre 2023",
              "checked": false,
              "rank": 16
            },
            {
              "id": 3743333,
              "label": "Octobre 2023",
              "checked": false,
              "rank": 17
            },
            {
              "id": 3743549,
              "label": "Août 2022",
              "checked": false,
              "rank": 3
            },
            {
              "id": 3743550,
              "label": "Septembre 2022",
              "checked": false,
              "rank": 4
            },
            {
              "id": 3743551,
              "label": "Juin 2022",
              "checked": false,
              "rank": 1
            },
            {
              "id": 3743552,
              "label": "Juillet 2022",
              "checked": false,
              "rank": 2
            },
            {
              "id": 3743557,
              "label": "Mai 2022",
              "checked": false,
              "rank": 0
            }
          ]
        },
        "id": 189035,
        "name": "Période",
        "code": "periode",
        "description": "",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      },
      {
        "value": "1253;",
        "type": "simple-text",
        "parameters": {
          "default_value": null,
          "char_min": null,
          "char_max": null
        },
        "id": 189097,
        "name": "User ID Flux",
        "code": "useridflux",
        "description": "",
        "mandatory": false,
        "rank": 0,
        "related_objects": [
          "document"
        ],
        "customfield_group": {
          "id": 0,
          "name": "",
          "code": "",
          "open_by_default": true
        }
      }
    ],
    "pagination": {
      "limit": 25,
      "count": 6,
      "total": 6,
      "offset": "WyIxODkwOTciXQ=="
    }
  }
]
1 Like

Thanks so much @RomainMaltrud!

So it seems there are two steps to this - first, we need to identify the object with code=poleactivite in your dataset, then read the corresponding value and parameter details.

This is how it could look in a workflow:

This returns both id and label at the end of the flow:

Hope this helps! I’ve also posted recently over in this thread, explaining a bit more of these JMESPath search string work.

3 Likes

Sorry for my late answer @MutedJam , it tooks me time to understand how to adapt the code to my workflow.

IT WORKS !!!

Thank you so much ! This is awesome.

Thanks also for the post you’ve wrote about JMESPath, very useful !

1 Like

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