[erlang-questions] fast JSON parser in C

Chris Anderson <>
Fri Jul 25 17:38:01 CEST 2008


On Fri, Jul 25, 2008 at 12:42 AM, Richard A. O'Keefe <> wrote:
>
> So I expect
>        {"foo":1, "bar":2}
> to become
>        [{foo,1},{bar,2}]
> -- though there is a "security" option in the EEP to force
>        [{<<"foo">>,1},{<<"bar">>,2}]
> and the only major question in my mind was whether it should be sorted,
> so that you can give one to orddict.

Joe mentioned not using atoms as keys due to the atom table not being
GC'd. The other consideration is making it unambigious between JSON
arrays and JSON objects.

{{"foo",1},{"bar",2}}, or even {[{"foo",1},{"bar",2}]} is unambiguous,
whereas [{"foo",1},{"bar",2}] requires deeper inspection to
differentiate it from a JSON array, if those were encoded as for
instance:

["foo","bar",1]

It make sense to me to encode JSON arrays as Erlang lists, for the
sake of simplicity. I agree that [{"foo",1},{"bar",2}] is easier to
work with than the pure tuple version, which makes me lean toward
using the outer wrapping {} as a marker for object-ness. That is, I
think {[{"foo",1},{"bar",2}]} is both unambiguous and easy to work
with. In this case, the empty JSON object {} is encoded as {[]}.

As far as sorting goes, I'd think it would be better not to
automatically reorder, as the user can do that if necessary, and while
the JSON spec doesn't preserve order, at least a few of the JS
interpreters do (including Spidermonkey, used by CouchDB). I don't
know if anyone is leaning on that feature yet, but it seems
potentially useful.

Chris

-- 
Chris Anderson
http://jchris.mfdz.com



More information about the erlang-questions mailing list