Skip to content

yq does not parse quoted keys correctly when searching through a list conditionally #2381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oren-cohen opened this issue May 27, 2025 · 0 comments
Labels

Comments

@oren-cohen
Copy link

Describe the bug
Error: 3:5: lexer: invalid input text "if .key == "topo..."

Version of yq: 4.X.X
Operating system: mac/linux/windows/....
Installed via: docker/binary release/homebrew/snap/...

mac homebrew
yq (https://github.com/mikefarah/yq/) version v4.45.4

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
input.yml:

spec:
    spec:
      requirements:
        - key: "kubernetes.io/arch"
          operator: In
          values: ["amd64"]
        - key: "topology.kubernetes.io/zone"
          operator: In
          values: ["eu-west-1a", "eu-west-1c"]

output.yml:

spec:
    spec:
      requirements:
        - key: "kubernetes.io/arch"
          operator: In
          values: ["amd64"]
        - key: "topology.kubernetes.io/zone"
          operator: In
          values: ["eu-west-1b", "eu-west-1a"]

Command
The command you ran:

AZS='["eu-west-1b","eu-west-1a"]' 
yq -i '.spec.template.spec.requirements[] |= if .key == "topology.kubernetes.io/zone" then .values = (env.AZS | from_json) else . end' argo-apps/karpenter/provisioners/base-nodepool.yaml

Actual behavior

Error: 1:39: lexer: invalid input text "if .key == \"topo..."

Expected behavior

It should replace whatever is in the values in the key: "topology.kubernetes.io/zone" with: ["eu-west-1b", "eu-west-1a"]

Additional context
I was able to get it to work by using the below command (simple array lookup) but what if someone juggles these around? Would be nice to lookup by key but obviously I am doing it wrong or it is unsupported.

yq -i '.spec.template.spec.requirements[1].values = env(AZS)' argo-apps/karpenter/provisioners/base-nodepool.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant