aalmiray/Json-lib — Issue #5: Issue with String escaping in JSONObject
Author: softwareresearchwork
Created: 2011-10-17 17:30:01+00:00
State: open

Code:

```java
JSONObject json = new JSONObject();
json.put("key1", "[...]");
json.put("key2", "[title]");
System.out.println(json.toString());
```

Output:

```javascript
{"key1":["..."],"key2":"[title]"}
```

Many of our String data values are enclosed in square brackets. For key1, the data is ```[...]``` but the String value is converted into an array while converting to JSON. For key2, it is correctly serialized as a String.

Is there any way to prevent this by escaping the data or using some settings ?

Thanks.