Fix "error converting YAML to JSON: did not find expected key" in Kubernetes
Codemia Knowledge Hub ·
"did not find expected key" means the YAML parser hit a token it did not expect because the document's structure is broken, usually from improper indentation, a missing colon, or a wrong key-value relationship. Kubernetes (and tools such as Helm) convert your YAML manifest to JSON before sending it to the API, so the error appears at that conversion step. Check the line number in the message and the lines just above it.
How a manifest maps from YAML to JSON
YAML expresses hierarchy through indentation; JSON uses braces and brackets. This Pod manifest:
becomes this JSON:
If the indentation is off, the parser cannot work out which key a line belongs to.
Common causes and fixes
Indentation errors
Incorrect indentation breaks the hierarchy:
Indent child keys consistently under their parent:
Missing colons or stray punctuation
A key without a colon, or extra characters, is another frequent cause:
Make sure every key is followed by a colon:
Inconsistent data types
Mixing types can also cause problems when converting YAML to JSON:
Keep the types consistent:
Validating YAML before you apply it
- YAML Lint validates YAML syntax and catches structural issues.
- yq is a command-line processor that handles YAML and can convert it to JSON.
- Online validators give real-time syntax checking.
You can also convert programmatically with Python's PyYAML, which reports a parse error instead of producing bad output:
To catch these errors before they reach a cluster, add YAML validation and conversion checks to your CI/CD pipeline, and test configuration files in a staging environment.
| Cause | Description | Solution |
| Indentation Errors | Misaligned spaces or tabs | Ensure consistent indentation |
| Missing Colons | Absence of a colon after a key | Include colons after each key |
| Inconsistent Data Types | Mixing strings and numbers unintentionally | Maintain consistent data types |
| Manual Conversion Errors | Human error during manual conversion | Use reliable automated tools |
Related reading
- Error creating pods is forbiddenpod failed quota namespace must specify limits.memory
- Error forwarding ports error upgrading connection Upgrade request required
- Error found in Chart.yaml, but missing in charts/ directory mysql
- Error found in requirements.yaml, but missing in charts/ directory dependency-chart
- Error converting YAML to JSON yaml line 15 did not find expected alphabetic or numeric character
- error converting YAML to JSON yaml line 30 found unknown escape character
- Error from server BadRequest pod kubia-zgxn9 does not have a host assigned
- Error from server Timeout the server was unable to return a response in the time allotted, but may still be processing the request get nodes
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.