简体   繁体   English

JSONPath 过滤器不适用于包含嵌套 object 而不是数组的嵌套 json

[英]JSONPath filter not working on nested json that contains nested object instead of an array

I'm looking for a way to filter this JSON and retrieve only the cost when fid > 10我正在寻找一种方法来过滤此 JSON 并仅在 fid > 10 时检索成本

Working example, the parent prop is an array:工作示例, parent属性是一个数组:

 [
    {
        "id": 1,
        "properties": {
            "parent": [
                {
                    "fid": 10,
                    "cost": 100
                }
            ]
        }
    },
    {
        "id": 2,
        "properties": {
            "parent": [
                {
                    "fid": 20,
                    "cost": 200
                }
            ]
        }
    },
    {
        "id": 32,
        "properties": {
            "parent": [
                {
                    "fid": 30,
                    "cost": 300
                }
            ]
        }
    }
]

JSONPath = $[*].properties.parent[?(@['fid']>10)].cost JSONPath = $[*].properties.parent[?(@['fid']>10)].cost

result = [
  200,
  300
]

Not working example, the parent prop is now an object:不工作的例子, parent道具现在是 object:

[
    {
        "id": 1,
        "properties": {
            "parent": {
                "fid": 10,
                "cost": 100
            }
        }
    },
    {
        "id": 2,
        "properties": {
            "parent": {
                "fid": 20,
                "cost": 200
            }
        }
    },
    {
        "id": 32,
        "properties": {
            "parent": {
                "fid": 30,
                "cost": 300
            }
        }
    }
]

JSONPath = $[*].properties.parent[?(@['fid']>10)].cost JSONPath = $[*].properties.parent[?(@['fid']>10)].cost

The result is No match结果是No match

try this尝试这个

$[?(@.properties.parent.fid>10)].properties.parent.cost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM