Home > Article > Backend Development > helm : Error converting YAML to JSON: yaml: line xx: Expected key not found
php editor Zimo helm is a popular Kubernetes package manager used to simplify the deployment and management of applications. However, sometimes you may encounter errors while converting YAML files to JSON format. One of the common errors is "helm: error converting YAML to JSON: yaml: line xx: could not find expected key". This error usually means that an expected key is missing at line xx of the YAML file. In this article, we will delve into the causes of this error and provide solutions to fix it.
There is a json encoded string in my values.yaml file->
values.yaml
network: cidrs : "[\"123.123.123.123/32\",\"123.124.125.125/32\"]"
Now I want to use this value as a list of strings in my network policy exit ipblock. But I can't convert it to a list.
Currently, I am following this method to achieve the requirement, but it failed -
error converting yaml to json: yaml: line xx : did not find expected key
netpol.yaml
spec: podSelector: matchLabels: name: log-forwarder policyTypes: - Egress egress: {{- $json := .Values.network.cidrs | fromJson -}} {{- range $json }} - to: - ipBlock: cidr: {{- . }} {{- end }} ports: - protocol: TCP port: 443
Any idea how to convert an encoded string to a list of strings and use it in my network strategy?
Use mustFromJson
instead of fromJson
, recently encountered the same problem and fixed it, check the documentation to find out why .
EDIT: For some reason fromJson
can't handle the top level list, but mustFromJson
can, looks like a bug since the only difference listed in the documentation is mustFromJson
Return an error if the JSON is invalid.
The above is the detailed content of helm : Error converting YAML to JSON: yaml: line xx: Expected key not found. For more information, please follow other related articles on the PHP Chinese website!