Home > Net >  How to use sed substitution to return the value in JSON key:value pair?
How to use sed substitution to return the value in JSON key:value pair?

Time:10-06

How do I get the value "GET" only?

$ echo '"parameters":[],"method":"GET","uri":"example.com/abc/def/"' | sed 's/\"method\":\(.*\)\,/\1/'

This removes "method": but I need the key/value pair of parameters and uri removed, as well. Here's the result as it is

"parameters":[],"GET""uri":"example.com/abc/def/"

CodePudding user response:

I might have figured it out.

$ echo '"parameters":[],"method":"GET","uri":"example.com/abc/def/"' | sed 's/^.*\"method\":\(.*\)\,.*$/\1/g

Please feel free to suggest better answers.

  • Related