0

我试图获取 JSONPath 表达式来过滤我的 JSON 并使用子数组的值获取整个运动对象。

我有以下 JSON:

[{

        "name": "Soccer",
        "regions": [{
                "name": "Australia",
                "leagues": [{
                        "name": "Australia league",
                        "inplay": 5,
                    }
                ]
            }
        ]
    }, {

        "name": "Tennis",
        "regions": [{
                "name": "Germany",
                "leagues": [{
                        "name": "Germany league",
                        "inplay": 0,
                    }
                ]
            }
        ]
    }
]

我需要使用 JsonPath 表达式获取“inplay == 0”的整个运动对象。

结果应如下所示:

 {

    "name": "Tennis",
    "regions": [{
            "name": "Germany",
            "leagues": [{
                    "name": "Germany league",
                    "inplay": 0,
                }
            ]
        }
    ]
}

地区和联赛计数可以> 1 因此$[?(@.regions[0].leagues[0].inplay == 0)]不适合

试过$[?(@.regions[*].leagues[*].inplay == 0)],但它不起作用

4

2 回答 2

0

由于 JayWay JSONPath 不直接支持(截至目前),我们将contains其用作解决方法

$[?(@.regions..inplay contains '0')]

注意:看起来 contains 的工作方式类似于 'like' 运算符或instr函数,但此处并非如此。如果该inplay值包含 0,例如10它不会提取记录(根据我的测试;)

于 2021-08-26T01:12:19.037 回答
0

这对我有用

$[?(@.regions[0].leagues[0].inplay == 0)]
于 2021-08-24T13:33:55.983 回答