0

So I have an api call that can output something such as this

{"access_token":"eyJjdHkiO_bxYJOOn28y5HGtGHgJzHVCE8zfy1qRBf_rhchA","token_type":"bearer","expires_in":900}

If I wanted to take that output and pull out just the content within the second set of quotes (the token), and put it into a variable for use in the script, what would be the easiest method of doing this?

  • One shell at a time, please. bash and zsh are not the same shell -- neither is fully compatible with the other (bash tries to be a superset of POSIX sh, whereas zsh is deliberately incompatible in places where its authors think POSIX standardized bad ideas); when you use two tags for mutually-incompatible languages, it creates ambiguity as to which of them an answer should be built for or evaluated against. – Charles Duffy Mar 10 '23 at 22:19
  • That said, piping to `jq -r '.token_type'` is generally the right thing here. If you don't have and can't install jq, see the linked duplicate for answers using Python's JSON parser instead; there are a variety of other answers on there using JSON-unaware tools, but they're all worse -- meaning they'll fail to parse some data that jq will handle correctly. – Charles Duffy Mar 10 '23 at 22:20
  • thank you, apologies as I'm pretty inexperienced and learning. I will look through this. – TrueZeldaFan Mar 11 '23 at 23:16

0 Answers0