1

How can I use a JMESPath query to filter a property Name which starts with abc, and ends with a timestamp in the format YYYYMMDD-HH, for example: abc-20230913-11.

I know how to filter a string using starts_with and ends_with, but I am not sure how to filter a string that ends with a timestamp format YYYYMMDD-HH.

--query 'Clusters[?
           starts_with(Name, `abc`) == `true` 
           && ends_with(Name, ???)
         ].[Name]'
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
user389955
  • 9,605
  • 14
  • 56
  • 98
  • JSON does not understand dates, or at least [there is no date type](https://stackoverflow.com/questions/10286204/what-is-the-right-json-date-format), so, in the same vain, JMESPath does not have any understanding of a date either. And since [there is no regex to accomplish this either](https://github.com/jmespath/jmespath.jep/issues/23), your requirement is not something achievable in JMESPath for the moment. – β.εηοιτ.βε Jul 16 '23 at 19:26
  • What you could do, though, for a workaround, is to parse your resulting JSON with a library like [tag:jq]: https://stackoverflow.com/questions/39881728/jq-filter-json-by-dates – β.εηοιτ.βε Jul 16 '23 at 19:27

0 Answers0