[eeps] EEP 18 - JSON bifs; object representation

Raimo Niskanen <>
Fri Aug 15 10:14:35 CEST 2008


I just want to vote for the tuple of one list
representation for an JSON object.

The in the EEP currently prefered list of tuples
representation has a few backdraws.
1) At the outer level it is a list, which is the
   chosen representation for a JSON sequence,
   so you will have to at least check the 
   first list element to see if it is an object.
2) The empty object becomes [{}] which is an anomaly
   since non-empty objects are lists of 2-tuples.
   This becomes a special case to handle.

The tuple of one list representation does not have
these backdraws.

The EEP argues that the proplists module can handle
the special case [{}] as well as lists of 2-tuples
and that should be an argument for the list of tuples
representation. I think that the tuple of one list
representation is just as easy to use since you
first match on the surrounding tuple and thereby
easily get a list to use the proplists module on:

foo(Json, Key) ->
    case Json of
        {L} -> % JSON object
            proplists:get_value(Key, L);
        L when is_list(L) -> % JSON sequence
            [foo(J) || J <- L];
        _ ->
            other(Json, Key)
    end.
-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the eeps mailing list