I have in github actions a list of words with spaces in the shell Bash. e.g.
hello1 hello2 hello3
The goal is to convert this list to a JSON array format, write it to the output variable and use it as a strategy matrix via fromJSON()
.
GITHUB_OUTPUT
.['hello1','hello2','hello3']
that can be used in the next job in the strategy matrix.Thank you for your help.
You could use jq
- either treating standard input as raw input
$ echo hello1 hello2 hello3 | jq --raw-input 'split(" ")'
[
"hello1",
"hello2",
"hello3"
]
or passing the string as a variable
$ var='hello1 hello2 hello3'
$ jq --null-input --arg str "$var" '$str | split(" ")'
[
"hello1",
"hello2",
"hello3"
]