Closed AkikoOrenji closed 1 year ago
Hi @AkikoOrenji , while RemesPath is JMESPath-inspired, there are a number of substantial departures from JMESPath syntax, as you've experienced.
Try working with this JSON:
{
"tracks": [
{"objects": [
{"type": "vehicle", "name": "car"},
{"type": "animal", "name": "dog"}
]
},
{"objects": [
{"type": "vehicle", "name": "boat"},
{"type": "vegetable", "name": "spinach"}
]
}
]
}
and consider the query @.tracks[:].objects[:][@.type == vehicle]
This query will produce the JSON
[
[
{"type": "vehicle", "name": "car"}
],
[
{"type": "vehicle", "name": "boat"}
]
]
because the query's equivalent pseudocode is
let output = list()
let this = this['tracks'] # @.tracks
for each thing in this: # [:]
let suboutput = list()
let this = this['objects'] # .objects
for each thing in this: # [:]
if this['type'] == 'vehicle': # [@.type == vehicle]
suboutput.append(this)
if suboutput is not empty:
output.append(suboutput)
return output
Note that while in this example, I used unquoted strings, in general RemesPath uses backticks to enquote strings, like so:
@.`this is a quoted string`
.
This is perfect. Thanks
Sorry for perhaps a basic question but i have a json document that i can filter down on all the Objects i'm after using @.tracks[:].objects[:] however i wish to only show the objects where a value in one of the keys within those object equals a text string.
I noticed i can do something like this with jmespath using a filter projection e.g. machines[?state=='running'].name (from their examples). I can't see anything in the plugin documentation for this and when i try things like the following in the plugin query box i get unexpected character errors e.g. @.tracks[].objects[][?type=='vehicle'] or @.tracks[*].objects[?type=='vehicle']
Thanks in advance for any advice you can offer