Java Json Escape jsonEscape(String in)

Here you can find the source of jsonEscape(String in)

Description

Escape value to be used in JSON.

License

Open Source License

Parameter

Parameter Description
in value to escape

Return

JSON escaped value

Declaration

public static String jsonEscape(String in) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  w  w. ja va  2s  .c o  m
     * Escape value to be used in JSON.
     * 
     * @param in value to escape
     * @return JSON escaped value
     */
    public static String jsonEscape(String in) {
        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");
    }
}

Related

  1. escape4Json(String source)
  2. escapeJSON(String aText)
  3. jsonEscape(CharSequence s)
  4. jsonEscape(String s)
  5. JsonEscape(String str)
  6. jsonEscape(String str)
  7. jsonEscape(String string)