[erlang-questions] jiffy encoding

Paul Davis <>
Tue Jul 16 00:23:03 CEST 2013


Aggelos is correct that it's used to easily pattern match between an object
and a list when writing JSON processing functions. Other suggestions
required more creative means to make the distinction.

The reason specifically for the 1-tuple are mostly historical. CouchDB
originally used mochijson2 directly which uses the form {struct,
proplist()}. It was decided that the struct atom was superfluous so it got
dropped using mochijson2's optional callbacks.

At one point there was a thread between Joe Armstrong, Damien Katz, and Bob
Ippolito that settled on the 1-tuple version but that was before NIFs came
around and let anyone implement their own efficient JSON parsing. Since
NIFs there hasn't been much action around providing BIFs which has resulted
in no single format being blessed as the "official" representation.

AFAIK, the only other widely used format beyond the {proplist()} and
{struct, proplist()} format is from jsx [1] which uses proplists
exclusively. Alisdair (the author of JSX) and I have had many discussions
on the pros and cons of both formats but have only managed to agree to
disagree on which is better.

[1] https://github.com/talentdeficit/jsx


On Sat, Jul 13, 2013 at 11:07 AM, Andrew Ledvina <> wrote:

> The reason for the extra tuple list is to distinguish ambiguous cases
>> involving empty lists and empty objects. Mochijson takes a different
>> approach but something must be done to deal with the Erlang types available.
>>
>> ------------------------------
>>
>> Message: 9
>> Date: Sat, 13 Jul 2013 10:05:00 +0300
>> From: Aggelos Giantsios <>
>> To: Mike Oxford <>
>> Cc: Erlang Questions <>
>> Subject: Re: [erlang-questions] jiffy encoding
>> Message-ID:
>>         <
>> >
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>>
>> On Sat, Jul 13, 2013 at 3:58 AM, Mike Oxford <> wrote:
>>
>> > From the docs...
>> > {[{foo, bar}]}             -> {"foo": "bar"} -> {[{<<"foo">>,
>> <<"bar">>}]}
>> >
>> > Why does jiffy need the extra "tuple list" syntax?
>> > Anyone happen to know?
>> >
>>
>> Hello!
>>
>> I believe the notion is that an orddict is converted to a JSON dictionary.
>> I guess in order to distinguish an orddict from a regular list, they wrap
>> the orddict in a tuple.
>>
>> Aggelos
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://erlang.org/pipermail/erlang-questions/attachments/20130713/a890fa51/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>> End of erlang-questions Digest, Vol 121, Issue 7
>> ************************************************
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130715/2f2d26e6/attachment.html>


More information about the erlang-questions mailing list