[erlang-questions] json_to_term EEP

Chris Anderson jchris@REDACTED
Tue Jul 29 00:43:15 CEST 2008


Here's an example of (C):

>From the JSON: {"key":"value", "key2":"value2"}

(C - object as proplist): [{<<"key">>,<<"value">>}, {<<"key2">>, <<"value2">>}]

On Mon, Jul 28, 2008 at 2:51 PM, Paulo Sérgio Almeida <psa@REDACTED> wrote:
>
> The only problem (C) poses is distinguishing the empty object from an empty
> array. My solution (which I am almost happy about) is to represent the empty
> object as [{}]. This way:
>
> - objects can be distinguished from arrays, e.g. by the following function:
>
> is_object(O=[T|_]) when is_tuple(T) -> true;
> is_object(_) -> false.
>
> - we can use objects as proplists, use functions like lists:keysearch or
> list comprehensions like
>
> Keys = [V || {V,_} <- Object]
>
> which will work even for the special empty object [{}].

(C) seems promising to me now that I've convinced myself that there
aren't issues with nesting.

Thanks for the input, Paulo!

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



More information about the erlang-questions mailing list