Skip to content
Latchkey

GitHub Actions "You have an error in your yaml syntax" for a dynamic matrix in CI

A dynamic matrix built its JSON with string interpolation and produced malformed content: unquoted keys, single quotes, a trailing comma, or embedded newlines. GitHub or fromJSON then reports a yaml/JSON syntax error.

What this error means

The generated matrix fails to parse with "You have an error in your yaml syntax" or a JSON parse error, typically when the producing step assembled the string by hand.

Actions
Error: You have an error in your yaml syntax
while parsing a flow node
did not find expected node content

Common causes

Hand-built JSON with wrong quoting

Concatenating strings often produces single-quoted keys, missing quotes, or a trailing comma, none of which are valid JSON for fromJSON.

Newlines or shell expansion leaked into the value

A multi-line output or an unescaped variable injected a newline, so the value spanning $GITHUB_OUTPUT lines breaks parsing.

How to fix it

Generate JSON with a real tool

  1. Build the array or object with jq (or your language) instead of string concatenation.
  2. Emit compact output with jq -c so it stays on one line.
  3. Write it to $GITHUB_OUTPUT and consume it via fromJSON.
bash
matrix=$(jq -cn '{include: [{os:"ubuntu-latest"},{os:"macos-latest"}]}')
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"

Validate the JSON before using it

Pipe the generated value through jq . in the same step so a malformed matrix fails there with a clear message, not later in strategy evaluation.

bash
echo "$matrix" | jq . > /dev/null

How to prevent it

  • Never hand-concatenate matrix JSON; use jq or a script.
  • Emit single-line compact JSON to $GITHUB_OUTPUT.
  • Validate the value with jq before it reaches fromJSON.

Frequently asked questions

What causes ""error in your yaml syntax""?
Concatenating strings often produces single-quoted keys, missing quotes, or a trailing comma, none of which are valid JSON for fromJSON.
How do I fix "error in your yaml syntax"?
Generate JSON with a real tool

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card