How to escape a colon inside a datetime value in a JSON string How to escape a colon inside a datetime value in a JSON string json json

How to escape a colon inside a datetime value in a JSON string


If you surround your date/time object in double quotes, it should accept it.

This should work:

String jsonStr = "{\"sDate\":\"2013-06-15T09:30:09+0000\"}";


Strings are required to be quoted in JSON:

string  ""  " chars "

Your snippet is invalid, which is why the exception is thrown. You must surround the string value with double quotes.


The more interesting issue is for cases where the string is unknown. In case the format is known then it's reasonably easy to fix. Added as a utility to org.json here.