[erlang-questions] json_to_term EEP

Chris Anderson <>
Wed Jul 30 02:11:24 CEST 2008

I find this discussion very interesting. Thanks to everyone who has spoken up.

2008/7/28 Willem de Jong <>:
> How about a SAX-like API? See for
> example http://www.p6r.com/articles/2008/05/22/a-sax-like-parser-for-json/

CouchDB will definitely need a streaming JSON processor if we are to
handle giant documents without building them in memory. The example
SAX/JSON parser in C++ is a good read, it's making me want to
prototype something like that in Ruby. A SAX-like streaming tokenizer
seems like it could lend itself to a nice, lean implementation.

On the question of formats, I think any of the proplist formats would
be a good choice. Here's a look at is_array() for the proplist

is_array([{_,_}|_])  -> false;
is_array(T)          -> is_list(T).

is_array(T)          -> is_list(T).

is_array([T|_])      -> not is_tuple(T);
is_array(T)          -> is_list(T).

(B) has the simplest array/object test-functions and has the
parsing/writing advantage that it doesn't require you to look inside
each Erlang list, to see if it corresponds to a JSON array or object.
This means reading left-to-right you know immediately when you've
encountered a JSON array or object.

I'm not sure how heavy to weight the easy-to-read (especially as some
people could think of the {[]} format as harder to read due to the
extra {}.


Chris Anderson

More information about the erlang-questions mailing list