Interview Prep/GitHub Actions/Contexts, Expressions, Env & Outputs

What do `toJSON` and `fromJSON` do, and give a real use of each?

IntermediateConceptContexts, Expressions, Env & Outputs
Answer

toJSON(value) serializes a context to pretty JSON: run: echo '${{ toJSON(github.event) }}' for debugging (dump through env to avoid quoting issues). fromJSON(string) parses JSON into an object, array, boolean or number:

strategy:
  matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}
timeout-minutes: ${{ fromJSON(vars.DEPLOY_TIMEOUT) }}
if: fromJSON(inputs.run_e2e)

The second one is how you get a number from a string variable where a number is required.

All GitHub Actions questions Roadmap: GitHub Actions

More on Contexts, Expressions, Env & Outputs