How to Pass a JSON Object to a Reusable Workflow in GitHub Actions
Reusable workflow inputs are string, boolean, or number, so pass structured data as a JSON string and parse it with fromJSON.
Declare a string input, pass a JSON-encoded value with toJSON or a literal, then decode it inside the reusable workflow using the fromJSON expression function.
Steps
- Declare a
type: stringinput for the JSON payload. - Pass a JSON string from the caller (e.g. via
toJSON(...)). - Parse it inside the workflow with
fromJSON(inputs.<name>).
Reusable workflow
.github/workflows/build.yml
on:
workflow_call:
inputs:
config:
type: string
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo "Region is ${{ fromJSON(inputs.config).region }}"Caller workflow
.github/workflows/ci.yml
jobs:
build:
uses: my-org/ci/.github/workflows/build.yml@main
with:
config: '{"region":"us-east-1","replicas":3}'Related guides
How to Pass Inputs to a Reusable Workflow in GitHub ActionsSend typed values into a reusable GitHub Actions workflow by declaring workflow_call.inputs and supplying the…
How to Call a Reusable Workflow in a Matrix in GitHub ActionsFan out a reusable GitHub Actions workflow across many inputs by putting a strategy.matrix on the calling job…