Convert JSON to name/value pairs using jq for SH output
Example JSON:
{
"a": 1,
"b": "\"2"
}
Desired output:
a='1'
b='"2'
Script:
for var in $(echo '{"a":1,"b":"\"2"}' | jq -r 'with_entries(.value |= @sh) | to_entries[] | "\(.key)=\(.value)"'); do
echo $var
# do what you want with $var
done
Documentation:
Go to playground
Tweet