js impl

138 views
Skip to first unread message

rektide

unread,
Mar 7, 2010, 10:35:04 PM3/7/10
to BSON
I'm curious what suggestions people might have for making a JS impl of
BSON; which if any existing implementations might be ideal for
porting, what implementation gotchas I should expect to run into.

I'm just hoping to get a more compact JSON representation where it
matters the most: in the browser.

Michael Schurter

unread,
Mar 7, 2010, 11:28:57 PM3/7/10
to bs...@googlegroups.com

First of all BSON is not "more compact" than JSON. The JSON
'{"foo":"bar"}' is 14 bytes whereas the corresponding BSON is 18
bytes. In fact for even trivial objects such as '{'foo':'bar',
'baz':[1,2,3,4,5]}' (38 bytes), BSON is much larger (63 bytes).

While BSON is probably faster to parse than JSON, the latest versions
of major browsers (including IE8) support JSON natively.* If
performance is your concern I would imagine a JSON implementation
would be faster than a pure JavaScript BSON implementation (although
this may not be the case given the performance boosts of modern
JavaScript implementations).

BSON does have a richer set of datatypes, but if you're only working
with trusted JSON sources than you can use native JavaScript objects
in JSON by reverting to using the eval() function.

That being said I'm sure there are plenty of legitimate uses for a
JavaScript BSON implementation! Just wanted to make sure no one
confuses BSON for "JSON 2.0" as BSON and JSON have (subtly?) different
goals in mind.

HTH,
- schmichael

* http://en.wikipedia.org/wiki/JSON#Native_JSON

Reply all
Reply to author
Forward
0 new messages