如何用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
相关产品推荐
相关产品推荐

