I have the following json :
{
"dataset_1": {
"size_in_mb": 0.5,
"task": "clean",
"tags": ["apple", "banana", "strawberry"]
},
"dataset_2": {
"size_in_mb": 100,
"task": "split",
"tags": ["apple"]
},
"dataset_3": {
"size_in_mb": 1024,
"task": "clean",
"tags": ["strawberry"]
}
}
How do I :
I am able to query the properties of a dataset, but not able to extract the name of the dataset with a certain property. e.g I can get ["strawberry"], but not ["dataset_1", "dataset_3"] when "tags" contains "strawberry".
This question comes close, but basically says you can't use jmespath.
As you stated in a comment, re-normalizing the original dataset to use sequentially-enumerated collation (instead of object-keys for top-level collation) is usually the best way to go, if you want to do general-purpose queries with jmespath.
The Stackoverflow post that you linked to goes into a little more detail on that matter here
{
"dataset_1": {
"size_in_mb": 0.5,
"task": "clean",
"tags": ["apple", "banana", "strawberry"]
},
"dataset_2": {
"size_in_mb": 100,
"task": "split",
"tags": ["apple"]
},
"dataset_3": {
"size_in_mb": 1024,
"task": "clean",
"tags": ["strawberry"]
}
}
{"dataroot":[
{
"name": "dataset_1",
"size_in_mb": 0.5,
"task": "clean",
"tags": ["apple", "banana", "strawberry"]
},
{
"name": "dataset_2",
"size_in_mb": 100,
"task": "split",
"tags": ["apple", "banana", "strawberry"]
},
{
"name": "dataset_3",
"size_in_mb": 1024,
"task": "clean",
"tags": ["strawberry"]
}
]}