[erlang-questions] json_to_term EEP

Willem de Jong w.a.de.jong@REDACTED
Tue Jul 29 08:10:23 CEST 2008


Hi all,

How about a SAX-like API? See for example
http://www.p6r.com/articles/2008/05/22/a-sax-like-parser-for-json/. I
can imagine that it would be easy to create any of the forms proposed in
this thread based on such an API. On the other hand it would allow you to do
things that you wouldn't be able to do with a parser that produces a
complete representation at once (in particular: parsing very big documents),
and it would be better suitedt to support a 'data mapper' approach like the
Erlang ASN.1 implementation, Googles Protocol Buffers or erlsom.

Regards,
Willem


On 7/29/08, Richard A. O'Keefe <ok@REDACTED> wrote:
>
> On 29 Jul 2008, at 9:51 am, Paulo Sérgio Almeida wrote:
> > I think there is no doubt that lists will be more useful than
> > tuples. There is, however another option, that I have been using in
> > a json parser I wrote:
> >
> > (C) an object is simply a proplist, i.e. a list of tuples.
>
> This is in fact what I originally proposed,
> the tricky point being that {} is a legal empty object in JSON,
> and we can't map that to [] because that's the representation
> for the empty sequence [].
>
> (O) Original proposal: {} => {}, other objects => list of pairs
> (A) Armstrong version: object => tuple of pairs, no exceptions.
> (B) Object => {list of pairs}.
> (C) Almeida proposal: as (O) but {} => [{}].
>
> The arguments for usability of the result in Erlang are the
> arguments that originally had me proposing (O).
>
> However, I note that nothing stops us providing a range of
> handy-dandy functions that work on tuples of pairs.
>
> %(O)
> is_object({})        -> true;
> is_object([{_,_}|_]) -> true;
> is_object(_)         -> false.
>
> %(A)
> is_object(T)         -> is_tuple(T).
>
> %(B)
> is_object({T})       -> is_list(T).
>
> %(C)
> is_object([T|_])     -> is_tuple(T);
> is_object(_)         -> false.
>
> It's rather annoying to be so bothered about empty objects;
> do they occur in practical JSON?  Proposal (C) seems neat enough;
> the main problem is fitting the results with @type.
>
> --
> If stupidity were a crime, who'd 'scape hanging?
>
>
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080729/59f5eeae/attachment.htm>


More information about the erlang-questions mailing list