1

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
  • 113
  • 1
  • 6

1 Answers1

2

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
  • 78,509
  • 12
  • 109
  • 152