JSON/R: JSON notation extended with references management (useful for object graphs with cycles)
Java Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status

See http://cadrature.blogspot.fr/2015/06/jsonr.html

Why a new JSON parser?

JSON is well and good, but it has one shortcoming: the management of object references. When you have to serialize an object graph, with object cycles, JSON is lost.

I needed to serialize such a graph. So I wrote a JSON extension, dubbed "JSON/R" (JSON with references).

I wanted the parser to stay as pretty as the standard JSON's (see a previous article), with the same property: a parser with no backtrack.

I added two concepts: "heap" and "reference".

A "heap" is just an array with different brackets (< and >); its usage is that the objects in it are referenced by their position in the array. By convention, the root object of the graph (i.e. the one the serialization started from) is the first one, noted $0 (see below).

A "reference" is an index into the heap: noted $<integer>.

An example


The class is a simple pojo with a String value, a Date timestamp, and another Pojo reference. The example above shows two objects referencing each other.