This has been asked a million times and I know there are a million solns. However im restricted in that I cant install anything on this client server , so I have whatever bash can come up with :)
I'm referencing Parsing JSON with Unix tools and using this to read data and split into lines.
$ cat demo.json
{"rows":[{"name":"server1.domain.com","Access":"Owner","version":"99","Business":"Owner1","Owner2":"Main_Apprve","Owner1":"","Owner2":"","BUS":"Marketing","type":"data","Egroup":["ALPHA","BETA","GAMA","DELTA"],"Ename":["D","U","G","T","V"],"stage":"TEST"}]}
However as you can see it splits the "Egroup" and others with multiple entries into single lines making it a little bit more difficult.
cat demo.json | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}>
"rows":["name":"server1.domain.com"
"Access":"Owner"
"version":"99"
"Business":"Owner1"
"Owner2":"Main_Apprve"
"Owner1":""
"Owner2":""
"BUS":"Marketing"
"type":"data"
"Egroup":["ALPHA"
"BETA"
"GAMA"
"DELTA"]
"Ename":["D"
"U"
"G"
"T"
"V"]
"stage":"TEST"]
Im trying to capture the data so i can list using a shell script. How would you advise me to capture each variable and then reuse in reporting in a shell script?
grep -Po '"Egroup":.*?[^\\]",' demo.json
"Egroup":["ALPHA",
As you can see this wouldn't work for lines with more than 1 entry.
Thoughts appreciated. ( btw Im open to python and perl options but without having to install any extra modules to use with json )