我正在寻找JSONpath表达式,以仅在数组中包含另一个元素的情况下提取数组中的元素。
以下表达式返回所有元素;
$.differ.element[*]['id','alias']
这是JSON文件:
{
"differ": {
"element": [
{
"id": "Address",
"alias": [
"Information about address"
]
},
{
"id": "Address.extension",
"path": "Address.extension"
},
{
"id": "Address.extension:official",
"path": "Address.extension",
"alias": [
"Mark address"
]
}
]
}
}
这将产生以下输出:
[
"Address",
[
"Information about address"
],
"Address.extension",
"Address.extension:official",
[
"Mark address"
]
]
我想省略'Address.extension'元素,因为它没有别名。 我该如何实现?
答案 0 :(得分:0)
您可以尝试
$.differ.element[?(@.alias)]
将得到这样的输出:
[
{
"id":"Address",
"alias":[
"Information about address"
]
},
{
"id":"Address.extension:official",
"path":"Address.extension",
"alias":[
"Mark address"
]
}
]