Json 没有数组的路径查询
Json Path querying without an array
在下面 JSON 我试图找到一个 condition.Where 只有当 OrderNumber 不为空或 null 时我才想要结果。
条件我都试过了。但还没有为我工作的是:
> $..Item[?(@.OrderNumber)]
> $..Item[?(@.CurrentOrder.OrderNumber)]
如有任何建议,我们将不胜感激。
我正在这里测试我的查询 https://jsonpath.curiousconcept.com/
{
"Response": {
"ID": "123456",
"Items": {
"Item": [
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
}
]
}
}
}
$..Item[?(@.CurrentOrder.OrderNumber)]
是适合您的案例的正确JSON路径。
已知您使用的工具无法正常工作。例如参见 [=13=].
我用 JSONPath Online Evaluator 和 JSON
测试了上面的查询
{
"Response": {
"ID": "123456",
"Items": {
"Item": [
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
},
{
"CurrentOrder": {
"OrderNumber": "456",
"Status": ""
}
},
{
"CurrentOrder": {
"Status": ""
}
}
]
}
}
}
它给出了正确的结果:
[
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
},
{
"CurrentOrder": {
"OrderNumber": "456",
"Status": ""
}
}
]
在下面 JSON 我试图找到一个 condition.Where 只有当 OrderNumber 不为空或 null 时我才想要结果。
条件我都试过了。但还没有为我工作的是:
> $..Item[?(@.OrderNumber)]
> $..Item[?(@.CurrentOrder.OrderNumber)]
如有任何建议,我们将不胜感激。 我正在这里测试我的查询 https://jsonpath.curiousconcept.com/
{
"Response": {
"ID": "123456",
"Items": {
"Item": [
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
}
]
}
}
}
$..Item[?(@.CurrentOrder.OrderNumber)]
是适合您的案例的正确JSON路径。
已知您使用的工具无法正常工作。例如参见 [=13=].
我用 JSONPath Online Evaluator 和 JSON
测试了上面的查询{
"Response": {
"ID": "123456",
"Items": {
"Item": [
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
},
{
"CurrentOrder": {
"OrderNumber": "456",
"Status": ""
}
},
{
"CurrentOrder": {
"Status": ""
}
}
]
}
}
}
它给出了正确的结果:
[
{
"CurrentOrder": {
"OrderNumber": "123",
"Status": ""
}
},
{
"CurrentOrder": {
"OrderNumber": "456",
"Status": ""
}
}
]