I am using JSONAta library to pass through a complex object. I need to get the name of the keys if it matches a certain condition.
{
"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"
}
}
}
I want all the name of the keys whose pattern is equal to reference-data i.e. WTID, VCRSID, VMSID. How is it possible to do using JSONAta Query.
So far I have tried using below query:
**[$contains(pattern, 'reference-data')]
but this returns only the values and I am unable to refer to any of the keys.
If you're expecting
["WTID", "VCRSID","VMSID"]
as a result, then this is the solution:properties
object as an array.$key
insideproperties
object.pattern
property from the object from the previous step equals to"reference-data"
You can also play with the interactive version of this solution here.