[erlang-questions] Erlang APIs and JSON
Bob Ippolito
bob@REDACTED
Sat Aug 31 00:06:57 CEST 2013
On Fri, Aug 30, 2013 at 2:57 PM, Loïc Hoguin <essen@REDACTED> wrote:
> Hi Mark, long time no see!
>
>
> On 08/30/2013 10:41 PM, Garrett Smith wrote:
>
>> Hi Mark,
>>
>> On Fri, Aug 30, 2013 at 3:22 PM, Mark Allen <mallen@REDACTED>
>> wrote:
>>
>>> I am wondering if anyone has opinions on how to deserialize JSON HTTP
>>> request bodies into Erlang terms. Tuple wrapped proplists seems to be how
>>> it comes back from mochijson2:decode() and jiffy:decode(). Erlson returns
>>> orddicts hidden in a record-like syntax via a parse-transform.
>>>
>>
>> It's initially odd, but {Proplist} has emerged as a standard-ish
>> representation of a JSON associative array in Erlang. It's better IMO
>> than dealing with the "what is this list - a string or an array?"
>> question.
>>
>
> The question doesn't come up in jsx because it doesn't use strings. So you
> got Proplist instead of {Proplist} and <<"string">> instead of "string".
> The JSON is still checked to be valid utf-8 even if it gives you binaries
> at the end so no functionality is lost.
>
> I don't think one is more used than the other though.
How are 0-length arrays distinguished from 0-length proplists? This is why
mochijson2 wraps proplists as {struct,P}. It also uses binaries for
strings, and validates the UTF8.
-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130830/4a0a1ca1/attachment.htm>
More information about the erlang-questions
mailing list