[erlang-questions] json_to_term EEP

Richard A. O'Keefe <>
Tue Jul 29 03:13:07 CEST 2008


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?










More information about the erlang-questions mailing list