RISON, a compact JSON specially suited for URIs

I was looking for a way to efficiently pass data between cross-domain iframes using the location hash trick. The first thing that I checked was JSON but the payload gets huge when url encoded, then I tried with base64 encoding which helps but not very much. Finally I found RISON which in short is nothing more than a reformulation of JSON’s control characters to make them more URI friendly.

It’ll basically use ( instead of {, !( instead of [ or ! instead of \ to escape stuff. The result is quite good with savings of a 50% on average when url encoding the result. The only problem I had was that the source code no longer seems to be maintained and the only copy I could find was in the repository of a project in google code.

So I’ve implemented my own version taking as example JSON’s official reference implementation API and rolling in a really simple token based parser. It passes all the test fragments from RISON’s home page and the performance is quite good for moderately sized payloads.

The code is licensed under the liberal MIT License and can be downloaded from my subversion repository.