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

如何用JSON Path筛选值以$开头的JSON模板节点?

问题:筛选JSON中值以"$"开头的节点路径

我正在实现一种JSON模板机制,以下是简化后的AdaptiveCard JSON模板示例:

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Container",
            "isVisible": "$._has_content.success",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "$.result[0].text"
                },
                {
                    "type": "FactSet",
                    "facts": [
                        "$.success.*"
                    ]
                }
            ]
        },
        {
            "type": "Container",
            "style": "attention",
            "isVisible": "$._has_content.fail",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "Failures"
                },
                {
                    "type": "FactSet",
                    "facts": [
                        "$.fail.*"
                    ]
                }
            ]
        }
    ]
}

我需要筛选所有值以"$"开头的节点,目标节点路径如下:

$.body[0].isVisible
$.body[0].items[0].text
$.body[0].items[1].facts
$.body[1].isVisible
$.body[1].items[1].facts

我刚接触JSON Path,尝试过表达式 $.body..*[?(@.* =~ /^\$./)] 但没有成功。

更新:参考@gregsdennis的回答后,我找到了正确的表达式:$..[?(@ =~ /^[$]/)]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 18:07:14