Consider using a JSON-aware tool to create JSON documents. Doing so would remove the need to manually escape special characters like tabs, newline, double quotes etc. A single quote is actually a character that doesn't need to be escaped in JSON. You just need to make sure you're using the correct quotes for the shell to recognize your string properly.
The jo
tool from here is made to make creating JSON documents from the command line be really easy:
somevariable2='line1
line2
line3'
curl -s -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d "$( jo \
variable1="Value1" \
variable2="$somevariable2" \
variable3='String with "quotes"' \
variable4="It's raining!" \
variable5='\/\/\/\/\/' )" \
'https://www.hashemian.com/tools/form-post-tester.php'
or
somevariable2='line1
line2
line3'
jo \
variable1="Value1" \
variable2="$somevariable2" \
variable3='String with "quotes"' \
variable4="It's raining!" \
variable5='\/\/\/\/\/' |
curl -s -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d @- \
'https://www.hashemian.com/tools/form-post-tester.php'
The response for either piece of code is
The POSTed value is:
********************
{"variable1":"Value1","variable2":"line1\nline2\nline3","variable3":"String with \"quotes\"","variable4":"It's raining!","variable5":"/\\/\\/\\/\\/"}
********************
'....'\''....'
or'....'"'"'....'
curl [...] --data @mydata.json
?