mathewdenis / json-smart

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

New compression type: write JSON strings with added line breaks for readability #35

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is a feature request.

Sometimes you want to use a json object as a configuration file, or you just 
want to write it to disk to examine it. It would be nice to have a new 
JSONStyle.VERBOSE for use in JSONObject.toJSONString() that would add full line 
breaks after each name/value pair, and before and after braces. The benefit is 
that the JSON strings would be easier for humans to read.

The style used in http://jsonlint.com/ is a good one.

Original issue reported on code.google.com by ccleve.t...@gmail.com on 10 Dec 2012 at 8:52

GoogleCodeExporter commented 9 years ago

Original comment by uriel.chemouni on 3 Jan 2013 at 10:46

GoogleCodeExporter commented 9 years ago
A first version is available on the GIT.

I need one more hour to complete this patch.

Original comment by uriel.chemouni on 30 Jul 2013 at 7:04

GoogleCodeExporter commented 9 years ago
a very basic version had been released in Json-smart 1.2, but not in the 
Json-smart v2 branch.

so for the moment you can try thos use the class: JSONStyleIdent
ex:

public static void main(String[] args) {
    JSONStyleIdent i = new JSONStyleIdent();
    String j = "{'a':{'b':'c','d':'e'},f:[1,2,'XYZ']}".replace('\'', '"');
    Object obj = JSONValue.parse(j);
    System.out.println(JSONValue.toJSONString(obj, i));
}

Original comment by uriel.chemouni on 29 Aug 2013 at 9:54