Skip to content
Latchkey

kubectl "error parsing ...: error converting YAML to JSON" in CI - Fix it

kubectl could not parse the file as YAML before it ever reached the cluster. A tab character, misaligned indentation, an unquoted special value, or leftover template markup makes the YAML-to-JSON conversion fail at a specific line.

What this error means

A kubectl apply -f fails with error: error parsing deploy.yaml: error converting YAML to JSON: yaml: line 14: did not find expected key.

kubectl
error: error parsing deploy.yaml: error converting YAML to JSON: yaml: line 14:
did not find expected key

Common causes

Tabs or inconsistent indentation

YAML forbids tabs for indentation; a stray tab or a mix of indent widths breaks parsing at that line.

Unrendered template markup or unquoted values

Leftover {{ ... }} from a templating step, or an unquoted value containing : or @, produces invalid YAML.

How to fix it

Validate the YAML at the reported line

  1. Open the file at the line N from the message and fix the indentation or stray tab.
  2. Quote values that contain special characters.
  3. Confirm any templating step fully rendered before kubectl ran.
Terminal
# show non-printing characters to spot tabs
kubectl apply -f deploy.yaml --dry-run=client

Lint manifests in CI before applying

A YAML lint or client-side dry run catches parse errors as a fast gate.

Terminal
kubectl apply -f k8s/ --dry-run=client -o yaml > /dev/null

How to prevent it

  • Use spaces, never tabs, for YAML indentation.
  • Render templates fully before handing manifests to kubectl.
  • Add a YAML lint or --dry-run=client gate in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →