I want to replace the "\" character from a JSON string by a empty space. How can I do that?
replaceAll("\\","");
You can find a JSON library in your language that you can feed some appropriate data structure to, and let it work for you. In JSON the only characters you must escape are \, ", and control codes.
Escapes or unescapes a JSON string removing traces of offending characters that could prevent parsing. The following characters are reserved in JSON and must be properly escaped to be used in strings: Backspace is replaced with \b. Form feed is replaced with \f. Newline is replaced with \n.
Escapes or unescapes a JSON string removing traces of offending characters that could prevent parsing. The following characters are reserved in JSON and must be properly escaped to be used in strings: Backspace is replaced with b. Form feed is replaced with f. Newline is replaced with n.
The following characters are reserved in JSON and must be properly escaped to be used in strings: Backspace is replaced with \b. Form feed is replaced with \f. Newline is replaced with \n. Carriage return is replaced with \r. Tab is replaced with \t. Double quote is replaced with \". Backslash is replaced with \\.
The Description field I was passing has characters that JSON considers invalid characters. In order to use those characters they have to be escaped. typically with a backslash. Anyway, it was simple replace operation, although I used multiple compose.
If you simply use language or library functions to convert things to and from JSON, you'll never even need to know JSON's escaping rules. This is what the misguided question asker here ought to have done. A JSON string must be double-quoted, according to the specs, so you don't need to escape '.
I have found that the easiest and best way to remove all escape characters from your JSON string, is to pass the string into Regex.Unescape() method. This method returns a new string with no ecapes, even \n \t etc, are removed.
See this MSDN article for more details: Regex.Unescape Method (String) (System.Text.RegularExpressions)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With