English 中文(简体)
如果在一名JSON选择中发言的话?
原标题:If statement within a JSON selection?
The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty. AAA wants to draw more attention to this question:
Answer must work with N8N and jmespath,,,

在下文的JSON中,当价格为rpp=真实时,我试图选择原材料价值。 这有时可能是第一种价格,也可能是所列价格的任何N数,但大部分时间是无价格或无价=真实价格。

这是可能的吗?

例如,使用{[“价格”][“价值”] 确实选择了我的价格,但我希望是_rpp=真实价格。

谢谢。

{
    "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:https://docs.n8n.io/code-examples/expressions/jmespath/#an-alternative-to-arrow-Functions

问题回答

https://developer.mozilla.org

如果返回<代码>unfin,则意思是,在<代码>prices/code>阵列内未出现任何项目is_rpp=真实

$json.prices?.find(p => p.is_rrp)?.value

const $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
};

const rrpPrice = $json.prices?.find(p => p.is_rrp)?.value;

console.log(rrpPrice);  // 35
{{ $json.prices[?(@.is_rrp == true)].raw }}

prices>时,这将给你以原始价格价值。

注:根据具体执行情况,初等动物的表述可能有所不同。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.