CICD-034 · Generate compact JSON for a matrix
Encyclopedia · Variables, outputs and data flow · All snippets
Previous · CICD-033 · Next · CICD-035
1. Where it fits
- Placement Bash run step following checkout, or equivalent lab terminal.
- Prerequisites GitHub Actions job or equivalent Gitea version with environment file support.
- Platforms local-linux, github-actions, gitea-actions.
- Parameters
GITHUB_OUTPUT.
2. Copy the snippet
bash
rows=$(jq -cn '{python:["3.11","3.12"]}')
printf 'matrix=%s\n' "$rows" >> "$GITHUB_OUTPUT"3. How it works
jq produces one line of JSON, which is safe to place in a single GITHUB_OUTPUT record. The consumer can parse the value with fromJSON before matrix expansion.
4. Verify the result
Consume with fromJSON on the output. Raw multiline JSON breaks a single-line output protocol.
Validation syntax-validated (Bash parse). Status definitions.