I have JSON file like the below; I need to list only x or y values only using jq:
{
"x":[
"a",
"b",
"c"
],
"y":[
"d",
"e"
]
}
I need to get only x values like
a
b
c
How can I do that?
I have JSON file like the below; I need to list only x or y values only using jq:
{
"x":[
"a",
"b",
"c"
],
"y":[
"d",
"e"
]
}
I need to get only x values like
a
b
c
How can I do that?
Easy:
cat input.json | jq '.x[]'
.x
: get value of x
property[]
: access array elementsIf you want it as a valid JSON array, remove the []
part: .x
. --raw-output
/-r
outputs top-level strings without quotation marks, e.g.:
$ jq '.x' < input.json
[
"a",
"b",
"c"
]
$ jq '.x[]' < input.json
"a"
"b"
"c"
$ jq -r '.x[]' < input.json
a
b
c