[ANN] JSURL a small module to help with JSON in URL parameters.

Showing 1-4 of 4 messages
[ANN] JSURL a small module to help with JSON in URL parameters. Bruno Jouhier 11/4/11 4:24 PM
I find it rather clumsy to pass complex values (things that mix
objects and arrays for ex) via URL query parameters. Splitting into
several parameters quickly becomes hairy and very verbose. JSON + URL
encoding is also pretty verbose and hard to read because of all the
percent escaping. Needless to say JSON + base64 is even harder to
read.

So, I wrote a little module that tries to do things the JSON way but
with the very few characters that URL encoding leaves intact.

https://github.com/Sage/jsurl

Gotcha: this is non standard encoding and I only provided a JS
implementation so don't use it for public service APIs that may be
consumed by clients written in other languages (unless you are ready
to provide support for these languages).

Bruno



Re: JSURL a small module to help with JSON in URL parameters. alFReD the GODZilla 11/5/11 12:18 AM
Nice library. How fast is it?
Have you done any benchmarks comparing it with native JSON?
Re: JSURL a small module to help with JSON in URL parameters. Nuck 11/5/11 7:42 PM
What about something like Rison? http://mjtemplate.org/examples/rison.html
URL-safe and represents the same stuff as JSON?

On Nov 5, 12:18 am, alFReD the GODZilla <farid...@googlemail.com>
wrote:
Re: JSURL a small module to help with JSON in URL parameters. Bruno Jouhier 11/6/11 6:10 AM
@Alfred,

I wrote a small bench: https://gist.github.com/1342872

Results MacBook Pro + Lion + node 0.6.0:

JSURL.stringify: 1617
JSON.stringify: 152
JSON.stringify + URL encode: 1731
JSURL.parse: 985
JSON.parse: 134
URL decode + JSON.parse: 579

JSON is obviously much faster (not a big surprise).

But JSON + URI encode/decode is a fairer comparison. Here JSURL does a
bit better on stringify but is slower on parse.


@Peter

Thanks for the pointer. I looked at Rison (did not know about it). It
addresses the same problem. It find it a bit complex, though. A few
remarks:

1) Rison must be combined with a percent encoding/decoding pass. JSURL
does not because its output only contains characters that don't need
URL escaping.

2) Rison uses comma and colon. These characters are encoded by
encodeURIComponent. So you only get the advertised compression/
readability if you encode with encodeURI. Seems problematic because
the typical use case is to encode query parameter values and the
recommended method in this case is encodeURIComponent.

3) The idea of sorting keys to normalize and improve caching is
interesting (I hadn't thought about that). But it introduces overhead
and, as most URLs will be generated by programs, there is a good
chance that keys will come in a fixed order most of the time.

Bruno

On Nov 6, 3:42 am, Peter Lejeck <peter.lej...@gmail.com> wrote:
> What about something like Rison?http://mjtemplate.org/examples/rison.html