Jmespath help!

Hello! I am using the n8n Set Values node to reason a json and set values or variables using Expression filters. For the most part it is working but in the below JSON I am trying to get the prices raw value of 35 because it is the is_rrp = true value but for some reason I can never get it to work.

Here is an example of an expression I tried:

{{ $jmespath($json.prices, “[?is_rrp==true].value”) }}

but that returns [Array: [29]]

… and I have no idea why!

Any help is appreciated.

Thank you

{
    "position": 1,
    "title": "Apple USB-C to Lightning Cable (2 m)",
    "asin": "asintest",
    "link": "https://www.amazon.com/",
    "categories": [{
        "name": "Electronics",
        "id": "electronics"
    }],
    "image": "https://m.media-amazon.com/images/",
    "is_prime": true,
    "rating": 4.8,
    "ratings_total": 15213956,
    "prices": [{
            "symbol": "$",
            "value": 29,
            "currency": "USD",
            "raw": "$29.00",
            "name": "$29.00",
            "is_primary": true
        },
        {
            "symbol": "$",
            "value": 35,
            "currency": "USD",
            "raw": "$35.00",
            "name": "$29.00",
            "is_rrp": true
        }
    ],
    "price": {
        "symbol": "$",
        "value": 29,
        "currency": "USD",
        "raw": "$29.00",
        "name": "$29.00",
        "is_primary": true
    },
    "page": "1",
    "position_overall": 1
}

Hi @n8n_rookie, I feel you. As much as I love the idea of JMESPath it always takes me a while to comprehend it. Looking at their website suggests filtering a boolean value would work like this (so using backticks around the boolean value true:

[?is_rrp == `true`]

So your full expression could be this one:

{{ $jmespath($json.prices, "[?is_rrp == `true`] | [0].value") }}

Or as a full workflow:

Hope this helps!

2 Likes

YOU ROCK !!! THAT WORKED!!!

Incredible - this has been driving me crazy. I really appreciate YOUR help on solving this. Thank you!

1 Like

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