I'm using bash script that needs to read the JSON output and parse a value from different JSON variables or strings. Here's the sample output. It needs to read the value next to the Content
or from any other variable. Such as,
Lookup Content
and be able to print Value1
.
Lookup DeviceType
and be able to print Value4
Sample Ouput:
{"Content":"Value1","CreationMethod":"Value2","database":"Value3","DeviceType":"Value4"}
I tried the combination of sed and awk sed 's/["]/ /g' | awk '{print $4}'
, but only if the position of Content
remains the same in the output. otherwise in the different JSON output, the positioning of Content
changes that puts the value out of scope thus awk '{print $4}'
picks up the wrong value.
jq
, or any other JSON parser. Withsed
and orawk
, you would not only have to rely on the document always being formatted exactly the same way, but also do your own string decoding in case the data is JSON encoded. – Kusalananda Nov 08 '19 at 15:56grep
? – schrodingerscatcuriosity Nov 08 '19 at 16:10"Content":
and then only print theValue1
– Riz Nov 08 '19 at 16:22