In JSON only the backslash, double quote and ASCII control characters need to be escaped.
if ((val == null) || (val.length() == 0)) { return "\"\""; StringBuilder sb = new StringBuilder(); sb.append('"'); for (int i = 0; i < val.length(); i++) { char ch = val.charAt(i); switch (ch) { ...
if (text == null) { return "null"; StringBuilder buffer = new StringBuilder("\""); int length = text.length(); for (int i = 0; i < length; i++) { char ch = text.charAt(i); if (ch == '"') { ...