Mason: Yet Another Java JSON Parser

Now if you dont know what JSON is, it is Javascript Object Notation. It is a way of exchanging Javascript Objects between a server and a client. Your current javascript supports parsing of JSON Strings to Javasript objects, but NOT all server side languages support JSON Script parsing by default. Scala has something, but still i find it a little bit weak in the sense that you still do a lot of work to actually get you data back as you might want it.

The only JSON parser for java on www.json.org works, but for me, its too large a workhorse for such a small task as parsing a String into an object. On the JSON website, they have done a lot of work to describe a sort of BNF for what a JSON String looks like, so my solution is this, write a parser(I am comfortable with javacc) that parses JSON Strings and return simple everyday objects, not class wrappers.

A JSON string is either a List, A Map or any Value, so Mason is a parser that parses a JSON String and returns any of this value.

Its so simple to use and straight forward.

sample code?? I’ll show you some

            FileInputStream fis = new FileInputStream(new File("/home/trinisoftinc/src/mason/lib/test.json"));

            Mason parser = new Mason(fis);

            parser.parse();

            System.out.println("FINAL Map: " + parser.finalMap);

            System.out.println("FINAL Array: " + parser.finalArray);

If the file test.json is a List or A Value, only finalArray is populated. finalArray is an ArrayList, finalMap is an Hashtable.

Source Code: http://gitorious.org/projects/mason

Download Jar File + Example : http://naijadukes.net/mason.tar.gz

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: