Last active
February 14, 2017 21:32
-
-
Save jmcdice/cfdc12510fb978240f84f3da5e10ef1c to your computer and use it in GitHub Desktop.
Parsing json with jq.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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