Skip to content
Latchkey

GitHub Actions fromJSON Errors - Invalid JSON in a Dynamic Matrix

fromJSON received something that is not valid JSON - an empty string, plain text, or output that was never serialized - so the expression cannot parse it into an object or array.

What this error means

A workflow using fromJSON(...) fails to compile or errors at runtime parsing the value, often when feeding a matrix from a job output that was not valid JSON.

Actions annotation
The workflow is not valid. Error parsing fromJSON: Unexpected token while parsing value: e
# the output was "ext" not a JSON array like ["ext"]

Common causes

Output is not JSON

fromJSON needs a valid JSON string. A raw word, a space-separated list, or human text fails to parse.

Empty or missing output

If the producing step wrote nothing to GITHUB_OUTPUT, fromJSON gets an empty string, which is not valid JSON.

How to fix it

Emit valid JSON from the producer

Serialize the value as JSON (a quoted array/object) in the producing step before consuming it with fromJSON.

.github/workflows/ci.yml
- id: set
  run: echo 'matrix=["18","20","22"]' >> "$GITHUB_OUTPUT"
# consumer
strategy:
  matrix:
    node: ${{ fromJSON(needs.prep.outputs.matrix) }}

Validate the JSON before use

  1. Build JSON with a tool like jq -c so it is always well-formed.
  2. Echo the output string and confirm it parses (jq . <<< "$out").
  3. Default to a valid empty array "[]" and guard the consumer against it.

How to prevent it

  • Serialize matrix/list outputs with jq so they are valid JSON.
  • Echo and validate the JSON string before feeding fromJSON.
  • Default to a well-formed value and handle the empty case.

Related guides

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