[GH-ISSUE #1481] Error evaluating valid JSON with withJSON expression #762

Closed
opened 2026-03-01 21:46:09 +03:00 by kerem · 4 comments
Owner

Originally created by @20k-ultra on GitHub (Nov 29, 2022).
Original GitHub issue: https://github.com/nektos/act/issues/1481

Bug report info

act version:            0.2.33
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 16
Docker host:            DOCKER_HOST environment variable is unset/empty.
Sockets found:
	/var/run/docker.sock
Config files:           
	/home/mig/.actrc:
		-P ubuntu-latest=catthehacker/ubuntu:act-latest
		-P ubuntu-22.04=catthehacker/ubuntu:act-22.04
		-P ubuntu-20.04=catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.19.3
	Module path:           github.com/nektos/act
	Main version:          (devel)
	Main path:             github.com/nektos/act
	Main checksum:         
	Build settings:
		-compiler:            gc
		-trimpath:            true
		CGO_ENABLED:          1
		GOARCH:               amd64
		GOOS:                 linux
		GOAMD64:              v1
		vcs:                  git
		vcs.revision:         1a32c043c11504dca5589ad3ea77344c2b40d152
		vcs.time:             2022-11-07T13:56:47Z
		vcs.modified:         true
Docker Engine:
	Engine version:        20.10.21
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         systemd
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Arch Linux
	OS type:               linux
	OS version:            
	OS arch:               x86_64
	OS kernel:             6.0.8-zen1-1-zen
	OS CPU:                16
	OS memory:             31784 MB
	Security options:
		name=seccomp,profile=default
		name=cgroupns

Command used with act

act push -W sample_workflow.yml --env INPUT_RUNS_ON=ubuntu-latest

Describe issue

I have noticed so far for 2 places in workflows that, when you are using fromJSON expression, act will say the valid is not valid JSON.

When running a workflow which sets runs-on with something that uses the fromJSON expression, an error is thrown regardless of what the value passed to fromJSON is. If I remove the fromJSON expression and reference the value directly, it works.

The 2nd place I've noticed this same behaviour is when using fromJSON for a matrix.

No response

Workflow content

on: push
jobs:
  myjob:
    runs-on: ${{ fromJSON(inputs.runs_on) }}
    steps:
      - run: echo "hello"

Relevant log output

[build/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value
[build/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value
[build/myjob] 🚧  Skipping unsupported platform -- Try running with `-P =...`

Additional information

Using the following command to control an input:

act push -W sample_workflow.yml --env INPUT_RUNS_ON=ubuntu-latest

with this workflow file:

# sample_workflow.yml
on: push
jobs:
  myjob:
    runs-on: ${{ inputs.runs_on }} # <-- works
    # runs-on: ${{ fromJSON(inputs.runs_on) }} <-- does not work
    steps:
      - run: echo "hello"

https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson

Originally created by @20k-ultra on GitHub (Nov 29, 2022). Original GitHub issue: https://github.com/nektos/act/issues/1481 ### Bug report info ```plain text act version: 0.2.33 GOOS: linux GOARCH: amd64 NumCPU: 16 Docker host: DOCKER_HOST environment variable is unset/empty. Sockets found: /var/run/docker.sock Config files: /home/mig/.actrc: -P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 -P ubuntu-20.04=catthehacker/ubuntu:act-20.04 -P ubuntu-18.04=catthehacker/ubuntu:act-18.04 Build info: Go version: go1.19.3 Module path: github.com/nektos/act Main version: (devel) Main path: github.com/nektos/act Main checksum: Build settings: -compiler: gc -trimpath: true CGO_ENABLED: 1 GOARCH: amd64 GOOS: linux GOAMD64: v1 vcs: git vcs.revision: 1a32c043c11504dca5589ad3ea77344c2b40d152 vcs.time: 2022-11-07T13:56:47Z vcs.modified: true Docker Engine: Engine version: 20.10.21 Engine runtime: runc Cgroup version: 2 Cgroup driver: systemd Storage driver: overlay2 Registry URI: https://index.docker.io/v1/ OS: Arch Linux OS type: linux OS version: OS arch: x86_64 OS kernel: 6.0.8-zen1-1-zen OS CPU: 16 OS memory: 31784 MB Security options: name=seccomp,profile=default name=cgroupns ``` ### Command used with act ```sh act push -W sample_workflow.yml --env INPUT_RUNS_ON=ubuntu-latest ``` ### Describe issue I have noticed so far for 2 places in workflows that, when you are using `fromJSON` expression, act will say the valid is not valid JSON. When running a workflow which sets `runs-on` with something that uses the `fromJSON` expression, an error is thrown regardless of what the value passed to `fromJSON` is. If I remove the `fromJSON` expression and reference the value directly, it works. The 2nd place I've noticed this same behaviour is when using `fromJSON` for a matrix. ### Link to GitHub repository _No response_ ### Workflow content ```yml on: push jobs: myjob: runs-on: ${{ fromJSON(inputs.runs_on) }} steps: - run: echo "hello" ``` ### Relevant log output ```sh [build/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value [build/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value [build/myjob] 🚧 Skipping unsupported platform -- Try running with `-P =...` ``` ### Additional information Using the following command to control an input: ``` act push -W sample_workflow.yml --env INPUT_RUNS_ON=ubuntu-latest ``` with this workflow file: ``` # sample_workflow.yml on: push jobs: myjob: runs-on: ${{ inputs.runs_on }} # <-- works # runs-on: ${{ fromJSON(inputs.runs_on) }} <-- does not work steps: - run: echo "hello" ``` https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson
kerem 2026-03-01 21:46:09 +03:00
Author
Owner

@KnisterPeter commented on GitHub (Nov 29, 2022):

The characters ubuntu-latest are no valid JSON. The string "ubuntu-latest" would be.

<!-- gh-comment-id:1330224001 --> @KnisterPeter commented on GitHub (Nov 29, 2022): The characters `ubuntu-latest` are no valid JSON. The string `"ubuntu-latest"` would be.
Author
Owner

@20k-ultra commented on GitHub (Nov 29, 2022):

Thanks for fast response @KnisterPeter, you're correct that my initial command contained invalid JSON. Once I added the quotes act ran the workflow correctly.

act push -W sample_workflow.yml --env INPUT_RUNS_ON=\"ubuntu-latest\"

However, when I set the same environment variable in an env-file I get the invalid json error...am I doing something wrong again ?

$ cat inputs
INPUT_RUNS_ON=\"ubuntu-latest\"
$ act push -W sample_workflow.yml --env-file inputs 
[sample_workflow.yml/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value
[sample_workflow.yml/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value
[sample_workflow.yml/myjob] 🚧  Skipping unsupported platform -- Try running with `-P =...`
<!-- gh-comment-id:1330829967 --> @20k-ultra commented on GitHub (Nov 29, 2022): Thanks for fast response @KnisterPeter, you're correct that my initial command contained invalid JSON. Once I added the quotes act ran the workflow correctly. ``` act push -W sample_workflow.yml --env INPUT_RUNS_ON=\"ubuntu-latest\" ``` However, when I set the same environment variable in an env-file I get the invalid json error...am I doing something wrong again ? ``` $ cat inputs INPUT_RUNS_ON=\"ubuntu-latest\" $ act push -W sample_workflow.yml --env-file inputs [sample_workflow.yml/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value [sample_workflow.yml/myjob] Unable to interpolate expression 'format('{0}', fromJSON(inputs.runs_on))': Invalid JSON: invalid character 'u' looking for beginning of value [sample_workflow.yml/myjob] 🚧 Skipping unsupported platform -- Try running with `-P =...` ```
Author
Owner

@20k-ultra commented on GitHub (Nov 29, 2022):

Sorry for the ping. To escape the " in the env file you just have to use single ' around the double quotes...

$ cat inputs 
INPUT_RUNS_ON='"ubuntu-latest"'

works^

<!-- gh-comment-id:1330835301 --> @20k-ultra commented on GitHub (Nov 29, 2022): Sorry for the ping. To escape the `"` in the env file you just have to use single `'` around the double quotes... ``` $ cat inputs INPUT_RUNS_ON='"ubuntu-latest"' ``` works^
Author
Owner

@mcascone commented on GitHub (Apr 24, 2025):

But the non-quoted syntax works without issue on a real GitHub runner.

I was wrong here. My error was due to unknowingly passing empty strings to the fromJSON function.

When testing in act, I was running workflow_call reusable workflows directly. Based on this conversation, I created a kicker-offer workflow with a push trigger that calls the reusable workflow - and everything seems to flow correctly now!

<!-- gh-comment-id:2828279298 --> @mcascone commented on GitHub (Apr 24, 2025): ~~But the non-quoted syntax works without issue on a real GitHub runner.~~ I was wrong here. My error was due to unknowingly passing empty strings to the `fromJSON` function. When testing in `act`, I was running `workflow_call` reusable workflows directly. Based on [this conversation](https://github.com/nektos/act/issues/2047#issuecomment-2828774051), I created [a kicker-offer workflow with a `push` trigger that calls the reusable workflow](https://github.com/nektos/act/issues/2047#issuecomment-2831164361) - and everything seems to flow correctly now!
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#762
No description provided.