I have to be efficient so I can't use tools like
jq which loads up a big binary executable. I just want to escape double quotes in a string so it's safe for JSON. This isn't good enough:
echo ' bad \" string"' | sed 's/"/\\"/g'
because it will escape double quotes that are already escaped. Is there a way to replace double quotes only if they are not already escaped?