是否可以通过jsonpath查询过滤json以获取父母的特定键和孩子的特定键?
这是json:
{
"data": {
"paymentProviders": [
{
"currency": "USD",
"supported": true,
"providers": [
{
"fields": [],
"key": "paypal",
"maintenance": false,
"settings": [
{
"max": 10000,
"min": 100
}
],
"withdrawalFields": []
},
{
"fields": [],
"key": "moneta",
"maintenance": false,
"settings": [
{
"key": "deposits",
"max": 10000,
"min": 100
}
],
"withdrawalFields": []
}
]
},
{
"currency": "GBP",
"supported": true,
"providers": [
{
"fields": [],
"key": "directTransfer",
"maintenance": false,
"settings": [
{
"key": "deposits",
"max": 0,
"min": 100
}
],
"withdrawalFields": []
}
]
},
{
"currency": "EUR",
"supported": true,
"providers": [
{
"fields": [],
"key": "paypal",
"maintenance": false,
"settings": [
{
"key": "deposits",
"max": 10000,
"min": 100
}
],
"withdrawalFields": []
}
]
}
]
}
}
我只想从中获取“ currency”,“ providers.key”和“ providers.maintenance”,就像这样:
{
"data": {
"paymentProviders": [
{
"currency": "USD",
"providers": [
{
"key": "paypal",
"maintenance": false,
},
{
"key": "moneta",
"maintenance": false,
}
]
},
{
"currency": "GBP",
"providers": [
{
"key": "directTransfer",
"maintenance": false,
}
]
},
{
"currency": "EUR",
"providers": [
{
"key": "paypal",
"maintenance": false,
}
]
}
]
}
}
如果我使用
$ .. ['key','maintenance']
我会丢失“ currency”属性。
基本上,我想在另一个“联合运算符”模式中使用“联合运算符”模式,想法是:
$ .. [“ currency”,“提供者。['key','maintenance']”]
答案 0 :(得分:0)
尝试
$..['currency','key','maintenance']
您应该得到
[
"USD",
"paypal",
false,
"moneta",
false,
"deposits",
"GBP",
"directTransfer",
false,
"deposits",
"EUR",
"paypal",
false,
"deposits"
]
进行比较
请注意,jsonpath联合运算符将只为您提供一个值列表,而没有您想要的结果中包含的上下文元素。