I am trying to use jq
to parse information from the TVDB api. I need to pull a couple of fields and assign the values to variables that I can continue to use in my bash
script. I know I can easily assign the output to one variable through bash with variable="$(command)"
but I need the output to produce multiple variables and I don't want to make to use multiple commands.
I read this documentation:
https://stedolan.github.io/jq/manual/v1.5/#Advancedfeatures
but I don't know if this relevant to what I am trying to do.
jq '.data'
produces the following output:
[
{
"absoluteNumber": 51,
"airedEpisodeNumber": 6,
"airedSeason": 4,
"airedSeasonID": 680431,
"dvdEpisodeNumber": 6,
"dvdSeason": 4,
"episodeName": "We Will Rise",
"firstAired": "2017-03-15",
"id": 5939660,
"language": {
"episodeName": "en",
"overview": "en"
},
"lastUpdated": 1490769062,
"overview": "Clarke and Roan must work together in hostile territory in order to deliver an invaluable asset to Abby and her team."
}
]
I tried jq '.data | {episodeName:$name}'
and jq '.data | .episodeName as $name'
just to try and get one working. I don't understand the documentation or even if it's what I'm looking for. Is there a way to do what I am trying to do?
JSON
and the actual fields needed? – Margerymargetjq
docs are not user-friendly. SO's own list of questions taggedjq
and ranked by votes may help. – Syrinx.foo as $var
creates a jq variable. That variable doesn't last beyond the point in time whenjq
exits. If you want a bash variable, you need to do that with... well... bash facilities. – Chapelbash
might be more appropriate. – Amaral