Skip to content

Instantly share code, notes, and snippets.

@jmcdice
Last active February 14, 2017 21:32
Show Gist options
  • Save jmcdice/cfdc12510fb978240f84f3da5e10ef1c to your computer and use it in GitHub Desktop.
Save jmcdice/cfdc12510fb978240f84f3da5e10ef1c to your computer and use it in GitHub Desktop.
Parsing json with jq.
$ cat test.json
[
{
"kind": "workspace",
"id": 672699,
"name": "Iteration 0",
"person_id": 2179801,
"project_ids": [
1968761,
1968571,
1966561,
1969757,
1968697,
1968861
]
}
]
$ cat test.json | jq '.[].project_ids'
[
1968761,
1968571,
1966561,
1969757,
1968697,
1968861
]
I want to get:
1968761
1968571
1966561
1969757
1968697
1968861
This works:
cat test.json | jq '.[].project_ids' | perl -lane 'print $1 if (/(\d+)/)'
1968761
1968571
1966561
1969757
1968697
1968861
Want it in jq instead.
@pakiheart
Copy link

cat test.json | jq '.[].project_ids | .[]'

→ cat test.json
[
{
"kind": "workspace",
"id": 672699,
"name": "Iteration 0",
"person_id": 2179801,
"project_ids": [
1968761,
1968571,
1966561,
1969757,
1968697,
1968861
]
}
]

→ cat test.json | jq '.[].project_ids | .[]'
1968761
1968571
1966561
1969757
1968697
1968861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment