Java Utililty Methods Json Escape

List of utility methods to do Json Escape

Description

The list of methods to do Json Escape are organized into topic(s).

Method

Stringescape4Json(String source)
escape Json
if (source == null) {
    return "";
StringBuilder buf = new StringBuilder();
CharacterIterator it = new StringCharacterIterator(source);
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
    if (c == '"') {
        buf.append("\\\"");
...
StringescapeJSON(String aText)
escape JSON
if (aText == null) {
    return null;
final StringBuilder result = new StringBuilder();
StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != StringCharacterIterator.DONE) {
    if (character == '\"') {
...
StringjsonEscape(CharSequence s)
Escapes json characters in the passed string
return s.toString().replace("\"", "\\\"").replace("[", "\\[").replace("]", "\\]").replace("{", "\\{")
        .replace("}", "\\}");
StringjsonEscape(String in)
Escape value to be used in JSON.
if (in == null || in.isEmpty())
    return in;
return in.replace("\\", "\\\\").replace("\n", "\\n").replace("\"", "\\\"").replace("\r", "\\r")
        .replace("\t", "\\t").replace("\b", "\\b").replace("\f", "\\f");
StringjsonEscape(String s)
json Escape
StringBuilder sb = new StringBuilder();
int len = s.length();
for (int i = 0; i < len; i++) {
    char ch = s.charAt(i);
    switch (ch) {
    case '"':
        sb.append("\\\"");
        break;
...
StringJsonEscape(String str)
Json Escape
return EscapeForHtml(str).replace("\\", "\\\\");
StringjsonEscape(String str)
json Escape
StringBuilder sb = new StringBuilder();
sb.append("\"");
for (int i = 0; i < str.length(); i++) {
    char ch = str.charAt(i);
    int found = -1;
    for (int k = 0; k < ESC_MAP.length && found == -1; k++) {
        if (ch == ESC_MAP[k])
            found = k;
...
StringjsonEscape(String string)
json Escape
if (string == null || string.length() == 0) {
    return "\"\"";
char c = 0;
int i;
int len = string.length();
StringBuilder sb = new StringBuilder(len + 4);
String t;
...
StringjsonEscapes(String str)
json Escapes
StringBuilder escaped = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
    switch (str.charAt(i)) {
    case 0:
        continue;
    case '\b':
        escaped.append("\\\\b");
        continue;
...