Sample Header Ad - 728x90

Parse value from different JSON strings (No jq)

2 votes
3 answers
7478 views
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.
Asked by Riz (59 rep)
Nov 8, 2019, 03:46 PM
Last activity: Aug 3, 2025, 12:04 AM