I am trying to use a bash variable to store json.
testConfig=",{
\"Classification\": \"mapred-site\",
\"Properties\": {
\"mapreduce.map.java.opts\": \"-Xmx2270m\",
\"mapreduce.map.memory.mb\": \"9712\"
}
}"
echo $testConfig Output: ,{
If I give it in a single line it works. But i would like to store values in my variable in a clean format.
I tried using cat >>ECHO That didn't work either
Any help is appreciated as to how I can store this in order to get the output in an expected format. Thanks.
jqgenerate it for you.testConfig=$(jq -n '{Classification: "mapred-site", Properties: { "mapreduce.map.java.opts": "-Xmx2270m", "mapreduce.map.memory.mb": "9712"}}'). For hard-coded snippets like this, it doesn't matter, but it's very important if you start trying to generate dynamic JSON using parameters with unknown values (e.g.,{foo: "$bar"}).testConfigbegins with a comma tells me you are building a larger JSON value usingtestCongfig, which makes the use ofjqmore important.