I need to get 'test2' value from a json string in bash. The only way I found with the minimum of dependency is to use perl regexp pattern like this:
echo '{"test1":1119,"test2":1118 }' | grep -Po '"test2":\K\d+'
1118
However, How could I achieve grep with a variable ? The following wont work becase $param is within single quote. I can't find a way around this
param="test2"
echo '{"test1":1119,"test2":1118 }' | grep -Po '"$param":\K\d+'
Any help would be greatly appreciated
jqthat can be used to parse JSON in bash.