org.json.simple.JSONObject.escape()
escapes quotes,, /, \r, \n, \b, \f, \t and other control characters.
import org.json.simple.JSONValue;
JSONValue.escape("test string");
Add pom.xml when using maven
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<scope>test</scope>
</dependency>