Wednesday, October 26, 2022

[SOLVED] How to use sed substitution to return the value in JSON key:value pair?

Issue

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/"

Solution

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.



Answered By - RJ Vega
Answer Checked By - Mary Flores (WPSolving Volunteer)