[GH-ISSUE #115] 'toJson' is not defined #77

Closed
opened 2026-03-01 21:39:53 +03:00 by kerem · 3 comments
Owner

Originally created by @Nuru on GitHub (Feb 28, 2020).
Original GitHub issue: https://github.com/nektos/act/issues/115

One example job in the GitHub Actions documentation uses toJson and it works when run on GitHub, but not when run by act.

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

runs fine on GitHub, but act complains:

[test/test] ⭐  Run Dump GitHub context
ERRO[0001] Unable to interpolate string '${{ toJson(github) }}' - [ReferenceError: 'toJson' is not defined] 
| ${{ toJson(github) }}
Originally created by @Nuru on GitHub (Feb 28, 2020). Original GitHub issue: https://github.com/nektos/act/issues/115 One [example job](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#example-printing-context-information-to-the-log-file) in the GitHub Actions documentation uses `toJson` and it works when run on GitHub, but not when run by `act`. ``` jobs: test: runs-on: ubuntu-latest steps: - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" ``` runs fine on GitHub, but `act` complains: ``` [test/test] ⭐ Run Dump GitHub context ERRO[0001] Unable to interpolate string '${{ toJson(github) }}' - [ReferenceError: 'toJson' is not defined] | ${{ toJson(github) }} ```
kerem 2026-03-01 21:39:53 +03:00
Author
Owner

@cplee commented on GitHub (Feb 28, 2020):

Looks like i was confused by the docs since the example they provided had:

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

Should be a quick fix here: https://github.com/nektos/act/blob/master/pkg/runner/expression.go#L169

<!-- gh-comment-id:592770185 --> @cplee commented on GitHub (Feb 28, 2020): Looks like i was confused by the [docs](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#tojson) since the example they provided had: > toJSON(job) might return { "status": "Success" } Should be a quick fix here: https://github.com/nektos/act/blob/master/pkg/runner/expression.go#L169
Author
Owner

@Nuru commented on GitHub (Feb 28, 2020):

@cplee It probably changed during development. I suggest you support both toJSON and toJson. Thanks for the quick turnaround!

<!-- gh-comment-id:592770901 --> @Nuru commented on GitHub (Feb 28, 2020): @cplee It probably changed during development. I suggest you support both `toJSON` and `toJson`. Thanks for the quick turnaround!
Author
Owner

@cplee commented on GitHub (Feb 28, 2020):

Will be included in next release.

<!-- gh-comment-id:592773986 --> @cplee commented on GitHub (Feb 28, 2020): Will be included in next release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#77
No description provided.