I'm using a 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 Input:
{"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. Withsedand 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.