There is a JSON of this type.

{"response":{"upload_url":"url"}} 

How can I pick up url using only shell? I did not understand JSON.awk, jq is not supported in my case

  • one
    Or maybe just a grep -oP '"upload_url":"\K[^"]+' ? - Mike
  • @Mike, where to read about regulars? I don’t have the patience to understand them :( - Flippy
  • @MaxU, I write a script in Android + Termux. Python is not accessible from root. - Flippy
  • for starters, you can en.wikipedia.org/wiki/… these are the basics. But \K - the beginning of the captured coincidence I don’t even know where it’s described, it’s from the pcre extension, but I don’t find any mention even of Larry Walla. goo.gl/XXogWS (chapter 5) - Mike

3 answers 3

To parse JSON on the command line, use the Jshon utility, it allows you to easily extract fields from an object of arbitrary complexity with automatic decoding of strings (if necessary). The program is written in pure C and only the Jansson library (apart from the standard libc ) requires dependencies.

For your case, the call will be like this:

 echo '{"response":{"upload_url":"url"}}' | jshon -e response -e upload_url -u 

It can be found in the Debian archive in the package of the same name.

  • Thank you so much, this option is the best. I just can't use it yet: D - Flippy
 upl=$(cut -d'"' -f6 <<<$mus) upload_url=$(echo $upl | tr -d '\') 

Works

    There is a cool fx https://github.com/antonmedv/fx

     $ echo '[1,2,3]' | fx "this.map(x => x * 2)" [2, 4, 6] 

    https://github.com/antonmedv/fx