yq icon indicating copy to clipboard operation
yq copied to clipboard

Looking for a way to escape period for yaml params that have dots in them

Open hferguson opened this issue 1 year ago • 1 comments

Please describe your feature request. A clear and concise description of what the request is and what it would solve. I would like to use yq to inject a parameter with dots and slashes in it. For example, I would like to represent the following which is an ingress annotation for helm:

globals: ingressAnnotations: cert-manager.io/cluster-issuer: letsencrypt

I tried appending this to my yaml file by using yq -i '.globals.ingressAnnotations.certmanager.io/cluster-issuer="letsencrypt"' values.yaml and this resulted in globals: ingressAnnotations: cert-manager: io/cert-manager: letsencrypt Maybe this exists already, but is there a way to escape dots so they aren't treated as delimiters? I already tried escaping the dot with a slash i.e. "cert-manager.io" but that only gave me the slash

The use case why I would do this has to do with OpenText Corporation's helm chart for Content Server deployments where you get the chart with a default values.yaml and you add/update by passing parameters to your helm install call

hferguson avatar Dec 21 '24 22:12 hferguson

You can accomplish this by enclosing the path element within quotes and square brackets. e.g.

yq -n '.globals.ingressAnnotations.["cert-manager.io/cluster-issuer"] = "letsencrypt"'
globals:
  ingressAnnotations:
    cert-manager.io/cluster-issuer: letsencrypt

Ref: https://mikefarah.gitbook.io/yq/operators/traverse-read#special-characters

sanchezma5 avatar May 31 '25 02:05 sanchezma5