Here is my string
{
\'user\': {
\'name\': \'abc\',
\'fx\': {
\'message\': {
\'color\': \'red\'
}
Everyone is talking about how to escape '
in a '
-quoted string literal. There's a much bigger issue here: single-quoted string literals aren't valid JSON. JSON is based on JavaScript, but it's not the same thing. If you're writing an object literal inside JavaScript code, fine; if you actually need JSON, you need to use "
.
With double-quoted strings, you won't need to escape the '
. (And if you did want a literal "
in the string, you'd use \"
.)