posix4e / json-smart

Automatically exported from code.google.com/p/json-smart
1 stars 0 forks source link

'/' is being escaped. why? #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The source code to reproduce a problem:
    @Test
    public void testJSON() {
        JSONObject object = new JSONObject();
        object.put("///////", "//////");
        System.out.println(object.toJSONString());
    }

Expected output:
{"\/\/\/\/\/\/\/":"\/\/\/\/\/\/"}
{"///////":"//////"}

I tried both 1.0.9 and 2.0.0-alpha1 versions, and the json-smart always escaped 
the "/" symbol. Isn't this pointless? Thanks.

Original issue reported on code.google.com by ruslanba...@gmail.com on 19 Sep 2011 at 6:46

GoogleCodeExporter commented 9 years ago
RFC 4627 standard required escaping / char, mainly for some javascript usage.
If you don’t want to escape / char you can also use:
JSONStyle style = new JSONStyle(JSONStyle.FLAG_PROTECT_4WEB); 
o.toJSONString(style);

or overwrite default compression method:
JSONValue.COMPRESSION = = new JSONStyle(JSONStyle.FLAG_PROTECT_4WEB); 
By the way Json-Smart wont escape / anymore by default.

I will add a JSONStyle.LIGHT_COMPRESS as predefined compression mode.

Original comment by uriel.chemouni on 20 Sep 2011 at 6:11

GoogleCodeExporter commented 9 years ago

Original comment by uriel.chemouni on 20 Sep 2011 at 6:27

GoogleCodeExporter commented 9 years ago
Uriel, thanks a lot for a helpful answer — that did the trick :)

Original comment by ruslanba...@gmail.com on 20 Sep 2011 at 10:13