5

input.json

{
  "Stack": {
    "KeypairNameB651C0C1": "key-0123456abcdefg",
    "AsgNameA7D05B90": "my-asg-name"
  }
}

The key names could vary, but will always begin with a set string

Similar question here but want to somehow get the value based on a select(startswith("AsgName")) for the key

Is this possible with jq?

tkwargs
  • 153

1 Answers1

6

You could use to_entries / with_entries to access the keys ex.

$ jq '.Stack | with_entries(select(.key | startswith("AsgName")))' file.json 
{
  "AsgNameA7D05B90": "my-asg-name"
}

or

$ jq '.Stack | to_entries[] | select(.key | startswith("AsgName")) | .value' input.json 
"my-asg-name"
steeldriver
  • 81,074