JSON.simple Tutorial
Selected Reading
- JSON.simple - Discussion
- JSON.simple - Useful Resources
- JSON.simple - Quick Guide
- Customized Output Streaming
- JSON.simple - Customized Output
- Primitive, Object, Map, List
- JSON.simple - Primitive, Map, List
- JSON.simple - Primitive, Object, Array
- JSON.simple - Merging Arrays
- JSON.simple - Merging Objects
- JSON.simple - Encode JSONArray
- JSON.simple - Encode JSONObject
- JSON.simple - Content Handler
- JSON.simple - Container Factory
- JSON.simple - Exception Handling
- JSON.simple - Using JSONValue
- Escaping Special Characters
- JSON.simple - JAVA Mapping
- JSON.simple - Environment Setup
- JSON.simple - Overview
- JSON.simple - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Escaping Special Characters
JSON.simple - Escaping Special Characters
The following characters are reserved characters and can not be used in JSON and must be properly escaped to be used in strings.
Backspace to be replaced with
Form feed to be replaced with f
Newpne to be replaced with
Carriage return to be replaced with
Tab to be replaced with
Double quote to be replaced with "
Backslash to be replaced with \
JSONObject.escape() method can be used to escape such reserved keywords in a JSON String. Following is the example −
Example
import org.json.simple.JSONObject; pubpc class JsonDemo { pubpc static void main(String[] args) { JSONObject jsonObject = new JSONObject(); String text = "Text with special character /" f ."; System.out.println(text); System.out.println("After escaping."); text = jsonObject.escape(text); System.out.println(text); } }
Output
Text with special character /" . After escaping. Text with special character /" f .Advertisements