JavaJson

JavaJson is an alternate implementation of JavaScript Object Notation (json) to that at json.org. The library uses a JavaCC based parser and is fairly small and is simple to use.

Examples

To parse a document from a string to a JsonObject:

JsonObject json = JsonObject.parse("{a:3, b:'hello world'}");

To generate a json string from a JsonObject:

System.out.println(json.toString);

To generate a json string from a JsonObject - pretty print with 2 spaces for tabs:

System.out.println(json.toString(2));

To read ints/strings, etc:

String b = json.getString("b");
int a = json.getInt("a");

JsonObjects rarely need exception handling, instead of throwing an exception if fields aren't set, nulls or 0's are returned, but if you care to check, you can:

String b = "...";
if (json.isString("b")) b = json.getString("b");

Links

JavaJson at SourceForge.net
View the Javadocs
Download