Skip to content
Latchkey

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: string input 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

Run this faster and cheaper on Latchkey managed runners. Start free →