Skip to content

Commit 9444c7b

Browse files
Sarah Edwardslucascosti
andauthored
Document how fromJSON can return a JSON data type (#17285)
Co-authored-by: Lucas Costi <lucascosti@users.noreply.github.com>
1 parent 2309a67 commit 9444c7b

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

content/actions/reference/context-and-expression-syntax-for-github-actions.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,27 @@ jobs:
186186
steps:
187187
- name: Dump GitHub context
188188
env:
189-
GITHUB_CONTEXT: ${{ toJson(github) }}
189+
GITHUB_CONTEXT: ${{ toJSON(github) }}
190190
run: echo "$GITHUB_CONTEXT"
191191
- name: Dump job context
192192
env:
193-
JOB_CONTEXT: ${{ toJson(job) }}
193+
JOB_CONTEXT: ${{ toJSON(job) }}
194194
run: echo "$JOB_CONTEXT"
195195
- name: Dump steps context
196196
env:
197-
STEPS_CONTEXT: ${{ toJson(steps) }}
197+
STEPS_CONTEXT: ${{ toJSON(steps) }}
198198
run: echo "$STEPS_CONTEXT"
199199
- name: Dump runner context
200200
env:
201-
RUNNER_CONTEXT: ${{ toJson(runner) }}
201+
RUNNER_CONTEXT: ${{ toJSON(runner) }}
202202
run: echo "$RUNNER_CONTEXT"
203203
- name: Dump strategy context
204204
env:
205-
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
205+
STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
206206
run: echo "$STRATEGY_CONTEXT"
207207
- name: Dump matrix context
208208
env:
209-
MATRIX_CONTEXT: ${{ toJson(matrix) }}
209+
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
210210
run: echo "$MATRIX_CONTEXT"
211211
```
212212
{% endraw %}
@@ -348,7 +348,7 @@ The value for `array` can be an array or a string. All values in `array` are con
348348

349349
`join(github.event.issue.labels.*.name, ', ')` may return 'bug, help wanted'
350350

351-
#### toJson
351+
#### toJSON
352352

353353
`toJSON(value)`
354354

@@ -358,13 +358,13 @@ Returns a pretty-print JSON representation of `value`. You can use this function
358358

359359
`toJSON(job)` might return `{ "status": "Success" }`
360360

361-
#### fromJson
361+
#### fromJSON
362362

363363
`fromJSON(value)`
364364

365-
Returns a JSON object for `value`. You can use this function to provide a JSON object as an evaluated expression.
365+
Returns a JSON object or JSON data type for `value`. You can use this function to provide a JSON object as an evaluated expression or to convert environment variables from a string.
366366

367-
##### Example
367+
##### Example returning a JSON object
368368

369369
This workflow sets a JSON matrix in one job, and passes it to the next job using an output and `fromJSON`.
370370

@@ -384,12 +384,33 @@ jobs:
384384
needs: job1
385385
runs-on: ubuntu-latest
386386
strategy:
387-
matrix: ${{fromJson(needs.job1.outputs.matrix)}}
387+
matrix: ${{fromJSON(needs.job1.outputs.matrix)}}
388388
steps:
389389
- run: build
390390
```
391391
{% endraw %}
392392

393+
##### Example returning a JSON data type
394+
395+
This workflow uses `fromJSON` to convert environment variables from a string to a Boolean or integer.
396+
397+
{% raw %}
398+
```yaml
399+
name: print
400+
on: push
401+
env:
402+
continue: true
403+
time: 3
404+
jobs:
405+
job1:
406+
runs-on: ubuntu-latest
407+
steps:
408+
- continue-on-error: ${{ fromJSON(env.continue) }}
409+
timeout-minutes: ${{ fromJSON(env.time) }}
410+
run: echo ...
411+
```
412+
{% endraw %}
413+
393414
#### hashFiles
394415

395416
`hashFiles(path)`

0 commit comments

Comments
 (0)