簡體   English   中英

JSONPath 過濾器不適用於包含嵌套 object 而不是數組的嵌套 json

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

我正在尋找一種方法來過濾此 JSON 並僅在 fid > 10 時檢索成本

工作示例, 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

result = [
  200,
  300
]

不工作的例子, 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

結果是No match

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM