I have a valid JSON values that is generated from using JQ from a string,
# key1:value1,key2:value2 --> {"key1":"value1","key2":"value2"}
input='key1:value1,key2:value2'
json=$( jq -Rc 'split(",") | map( split(":") | {(.[0]): .[1]}) add |' <<<"$input" )
echo $json
This works perfectly fine but now I want to convert the json to string without escaping the double quotes of each key and value and just need to add single quotes at the end.
# {"key1":"value1","key2":"value2"} ---> '{"key1":"value1","key2":"value2"}'
I tried the tostring function but it escapes all double quotes
strJson=$(jq tostring <<< "$json")
echo $strJson