admin管理员组文章数量:1399989
Given a collection (not an array) like this:
{
"field1": {
"type": "string",
"value": "test"
},
"field2": {
"type": "array",
"value": []
},
"field3": {
"type": "string",
"value": "test"
},
"field4": {
"type": "array",
"value": []
}
}
how do I end up with just (filtering on type="array"
):
{
"field2": {
"type": "array",
"value": []
},
"field4": {
"type": "array",
"value": []
}
}
Given a collection (not an array) like this:
{
"field1": {
"type": "string",
"value": "test"
},
"field2": {
"type": "array",
"value": []
},
"field3": {
"type": "string",
"value": "test"
},
"field4": {
"type": "array",
"value": []
}
}
how do I end up with just (filtering on type="array"
):
{
"field2": {
"type": "array",
"value": []
},
"field4": {
"type": "array",
"value": []
}
}
Share
Improve this question
edited Mar 24 at 17:25
jonrsharpe
122k30 gold badges268 silver badges475 bronze badges
asked Mar 24 at 17:23
L SzijL Szij
11 bronze badge
1 Answer
Reset to default 0The JSONata wildcard operator will select the values of all fields in the context object.
Option 1
$map($spread($), function($x){
$x.*.type = 'array' ? {
$keys($x): $x.*
}
})
JSONata Playground: https://jsonatastudio/playground/f5648325
Option 2
$.*[type="array"]
The output will look like:
[
{
"type": "array",
"value": []
},
{
"type": "array",
"value": []
}
]
JSONata Playground: https://jsonatastudio/playground/3007924a
本文标签: jsonFetch nonarray objects in collection with certain valueStack Overflow
版权声明:本文标题:json - Fetch non-array objects in collection with certain value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744237482a2596623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论