0

Gives the below JSON:

{
  "environments": [
    {"env": "dev", "description": "dev environment"},
    {"env": "dev01", "description": "dev01 environment"},
    {"env": "dev01b", "description": "dev01 blue environment"},
    {"env": "dev01g", "description": "dev01 green environment"}
  ]
}

I'm only interested in extracting dev01b and dev01g. Any environment with a digit followed by a letter.
In this case dev01b, dev01g.

I tried contains and ends_with functions and I was able to extract the required strings.

But, the number of environments keep increasing and I need to extract all these environment names with digit followed by letter in the end. And it is not sustainable to add ends_with function for all combinations of letters and digit.

I want to add some regex kind of grammar in the ends_with function and extract all the values.

Is it possible with JMESPath?

By the way, I'm using aws cli --query.

5
  • 3
    Your requirements are likely beyond what JMESPATH can offer. It would need regex matching, which JMESPATH doesn't seem to support. You could possibly filter the result with jq or write a Python script instead that uses boto3 to call AWS and do the filtering in Python code. Commented Apr 30 at 6:02
  • 1
    And sadly JMESPath doesn't treat string like a list a characters, so you cannot even expect 'dev01g'[5] to be equal to g Commented Apr 30 at 6:42
  • I want to understand what is this jmespath grammar trying to convey with different un-quoted string ranges for eg: %x61-7A) ; a-z jmespath.org/specification.html#grammar Commented Apr 30 at 9:16
  • 1
    Unclear what you want to know about the ABNF grammar. The unquoted-string grammar rule is used, for example, in the grammar rule for function-expression. And that's because JMESPath supports functions for example avg(@) or contains(@, 'menu'). Commented Apr 30 at 13:47
  • 1
    @dplvs the character 61 in hexadecimal (hence the x) is the character a in the ASCII table, the character 7A is the z; that's all. Ref: en.wikipedia.org/wiki/ASCII#Character_set Commented Apr 30 at 15:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.