Jason Stanley
Jason Stanley

Reputation: 457

Print values of keys with dot in it

I have a yaml file with the following format

---
users:
  [email protected]:
    - roles/role1
    - roles/role2
    - roles/role3

  [email protected]:
    - roles/role4
    - roles/role5
    - roles/role6

Now I would like to print the roles for [email protected]

Im trying to do the following

cat permissions.yaml | yq '.users[ [email protected]]'
jq: error: syntax error, unexpected FORMAT (Unix shell quoting issues?) at <top-level>, line 1:
.users[ [email protected]]
jq: 1 compile error

Is there a work around to this ?

Upvotes: 0

Views: 889

Answers (2)

pbatey
pbatey

Reputation: 1433

If you are using v3 (or later) of mikefarah/yq you can escape keys with quotes, like this:

cat permissions.yaml | yq e '.users."[email protected]"' -

or

cat permissions.yaml | yq e '.users["[email protected]"]' - 

Documented in v3 here and in v4 here.

I verified this with v4.13.4:

$ yq --version
yq (https://github.com/mikefarah/yq/) version 4.13.4

Upvotes: 2

Will Charlton
Will Charlton

Reputation: 922

Try removing the whitespace in front of your key:

cat permissions.yaml | yq '.users[[email protected]]'

That might resolve it.

Upvotes: 0

Related Questions