How should I escape strings in JSON?
Posted
by Bytecode Ninja
on Stack Overflow
See other posts from Stack Overflow
or by Bytecode Ninja
Published on 2010-06-11T03:54:16Z
Indexed on
2010/06/11
4:02 UTC
Read the original article
Hit count: 1167
When creating JSON data manually, how should I escape string fields? Should I use something like Apache Commons Lang's StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml, or should I use java.net.URLEncoder?
The problem is that when I use SEU.escapeHtml, it doesn't escape quotes and when I wrap the whole string in a pair of 's, a malformed JSON will be generated.
© Stack Overflow or respective owner