You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在N8N中筛选JSON里is_rrp=true的价格raw字段值?

在N8N中提取JSON数组里is_rrp=true的价格raw值

问题场景

给定如下结构的JSON数据,需要提取prices数组中is_rrp属性为true的价格项的raw字段值。符合条件的项可能在数组任意位置,多数情况无匹配项或仅有一个。目前已能通过{{ $json["price"]["value"] }}获取主价格,想确认是否能实现目标提取。

示例JSON:

{
    "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
}

解决方案

完全可行,在N8N中可以使用JMESPath表达式实现这个需求,具体表达式如下:

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

表达式说明

  • prices[?is_rrp == true]:从prices数组中筛选出所有is_rrp属性为true的对象
  • .raw:提取这些对象的raw字段值,得到一个包含匹配结果的数组
  • | [0]:取数组的第一个元素(因为多数情况只有一个匹配项,无匹配时会返回null)

针对示例JSON,这个表达式会返回$35.00,符合需求。

内容的提问来源于stack exchange,提问作者AAA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 13:30:02