navig8tr
navig8tr

Reputation: 1844

Filter results using Jmespath on one dimensional array

Using jmespath and given the below json, how would I filter so only JobNames starting with "analytics" are returned?

For more context, the json was returned by the aws cli command aws glue list-jobs

{
    "JobNames": [
        "analytics-job1",
        "analytics-job2",
        "team2-job"
  ]
}

Tried this

JobNames[?starts_with(JobNames, `analytics`)]

but it failed with

In function starts_with(), invalid type for value: None, expected one of: ['string'], received: "null"

Above I extracted the jmespath bit, but here is the entire aws cli command I tried and failed is this

aws glue list-jobs --query '{"as_string": to_string(JobNames[?starts_with(JobNames, `analytics`)])}'

Upvotes: 0

Views: 592

Answers (1)

Ersoy
Ersoy

Reputation: 9586

I couldn't test it on list-jobs but the query part works on list-crawlers. Just replaced the JobNames with CrawlerNames.

aws glue list-jobs --query 'JobNames[?starts_with(@, `analytics`) == `true`]'

Upvotes: 1

Related Questions