I'm using jq to extract an array from a JSON in a GitHub workflow:
name: Test
on:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Test
run: echo $(echo '{"value":[{"displayName":"test"}]}' | jq -c '.value.[]')
However, it fails with the error
Run echo $(echo '{"value":[{"displayName":"test"}]}' | jq -c '.value.[]')
jq: error: syntax error, unexpected '[', expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at <top-level>, line 1:
.value.[]
jq: 1 compile error
If I run the same command with jq locally, it works - why doesn't it work on a GitHub runner?
You're using .value.[]
; support for chained .[]
was added in jq 1.7 (see the release notes, under "language changes"), and ubuntu-22.04 Actions runners use jq 1.6.
You can fix it by using .value[]
instead.
Alternatively, you can run your job on an ubuntu-24.04
runner; they have jq 1.7.1 installed, but the image is currently (June 2024) in beta. ubuntu-latest
still uses 22.04.