我使用JSONAta库来传递一个复杂的对象。我需要得到钥匙的名字,如果它符合某一条件。
{
"properties": {
"WTID": {
"pattern": "reference-data",
"type": "string"
},
"VCRSID": {
"pattern": "reference-data",
"type": "string"
},
"VMSID": {
"pattern": "reference-data",
"type": "string"
},
"DroneID": {
"pattern": "unique-data",
"type": "string"
}
}
}
我想要其模式等于引用数据的所有键的名称,即WTID、VCRSID、VMSID。如何使用JSONAta查询。
到目前为止,我已经尝试使用以下查询:
**[$contains(pattern, 'reference-data')]
但是这只返回值,我无法引用任何键。
发布于 2022-04-11 01:39:35
如果您期望得到["WTID", "VCRSID","VMSID"]
,那么这就是解决方案:
$keys(properties) ~> $filter(function ($key) {
$lookup(properties, $key).pattern = "reference-data"
})
properties
对象的所有键作为数组。$key
中查找properties
对象中的值。pattern
属性等于"reference-data"
时才返回键您也可以使用这个解决方案的交互式版本在这里。
https://stackoverflow.com/questions/71819427
复制相似问题