Common causes
1. A sibling key indented by the wrong number of spaces
Here ports is indented by three spaces while image uses four. YAML cannot tell which mapping it belongs to. Align it exactly with its siblings.
web:
image: nginx:1.27
ports:
- "80:80"web:
image: nginx:1.27
ports:
- "80:80"2. Template output with the wrong indentation
In Helm, {{ toYaml .Values.resources }} keeps the indentation of the template line only for its first line. Use nindent (or indent) so every rendered line lands at the right level.
resources:
limits:
cpu: 500m
requests:
cpu: 250mresources:
limits:
cpu: 500m
requests:
cpu: 250m3. A missing colon after a key
Without the colon, image nginx is a plain scalar, and the next line makes it look like a multi-line key. This is what PyYAML and Go report as “could not find expected ‘:’”.
image nginx:1.27
ports:
- "80:80"image: nginx:1.27
ports:
- "80:80"4. An unclosed quote earlier in the file
A missing closing quote makes the string swallow the following lines, and the parser fails later where the structure no longer makes sense. Look for an odd number of quotes above the reported line.
name: "web
replicas: 2name: "web"
replicas: 2Frequently asked questions
Why does the error line not match where my mistake is?
Parsers report the point where the structure became impossible, which can be after the actual mistake. Check the reported line, the line above it, and any quotes that might still be open.
How many spaces should I indent YAML with?
Any consistent number works, but every key in the same mapping must start in the same column. Two spaces is the most common convention, and PasteKit can re-indent a file for you once it parses.
Why does the line number differ between tools?
Go, PyYAML and the yaml JavaScript library detect the problem at slightly different tokens. They all describe the same broken indentation, so fix the structure rather than chasing one tool’s line number.