You can (and must) use double-quotes, you just need to escape the double-quotes that are part of the string:
curl -X POST -d "{\"summary\": \"$summary\", \"description\": \"$description\", \"moduleMapAssets\": [{\"name\":\"Rates | IRD\"},{\"name\":\"CRD | CRD\"}]}" -H "Content-Type: application/json"
As @MikeHolt pointed out in a comment, it's also possible to mix quoting styles within a single string, so you could switch back and forth between single-quoted sections that include literal double-quotes, and double-quoted sections that include variable references:
curl -X POST -d '{"summary": "'"$summary"'", "description": "'"$description"'", "moduleMapAssets": [{"name":"Rates | IRD"},{"name":"CRD | CRD"}]}' -H "Content-Type: application/json"
To explain that in a little more detail: ... '{"summary": "'"$summary"'", "description"...'
is parsed as the single-quoted section '{"summary": "'
(within which the double-quotes are literal), followed immediately by the double-quoted section "$summary"
(within which the variable gets expanded), followed immediately by another single-quoted section '", "description"...'
etc. Since there are no spaces between these sections, they're treated as one long argument to curl
.
BTW, if any of your variables can contain double-quotes or backslashes themselves, things get much more complicated. If something like this is a possibility, you should be using something like jq
to create the string. Something like this:
jsonstring=$(jq -n --arg summary "$summary" --arg description "$description" '{
summary: $summary,
description: $description,
moduleMapAssets: [{name: "Rates | IRD"}, {name: "CRD | CRD"}]
}' )
curl -X POST -d "$jsonstring" -H "Content-Type: application/json"