Example JSON
[
{
"id": 12,
"clientName": "super-client"
},
{
"id": 15,
"clientName": "helloClient"
}
]
I want to use JMESPath to check if each clientName field does not contain the text super- and then display the result
I'm using the API connector tool for Google Sheets to parse a JSON I get via a call. I'm stuck with this.
Almost all the reference examples on JMESPath site have a named object or array. This JSON I have doesn't have any named objects.
I want to do something like
result = []
for entry in data:
if not entry['clientName'].find("super-"):
result.append(entry)
return result
In JMESPath, it is called a filter projection and it can be applied on an array right away, without it having to be named.
What you will need on top of a filter projection is the contains function and the not expression !.
All this together gives you this query:
[?!contains(clientName, 'super-')]
Which, on your JSON example will give, as a result:
[
{
"id": 15,
"clientName": "helloClient"
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With