[erlang-questions] [ANN] Erlson - dynamic name-value dictionary data type and syntax
James Aimonetti
james@REDACTED
Tue Aug 30 03:05:18 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 08/29/2011 05:12 PM, Bob Ippolito wrote:
> On Mon, Aug 29, 2011 at 4:53 PM, Loïc Hoguin <essen@REDACTED> wrote:
>> On 08/30/2011 01:36 AM, Jack Moffitt wrote:
>>>> May I suggest switching the decoded JSON format to that used by ejson
>>>> (https://github.com/benoitc/ejson) and jiffy
>>>> (https://github.com/davisp/jiffy) instead of the format used by
>>>> mochiweb/mochijson2. Most of the projects that make heavy use of JSON seem
>>>> to be moving to the format I'm suggesting.
>>>
>>> A tuple of an array of tuples seems less than elegant Why not just a
>>> tuple of tuples? Is scanning through a tuple significantly slower than
>>> scanning an array?
>>
>> This should explain the whys:
>>
>> http://www.erlang.org/eeps/eep-0018.html
>>
>>> As far as formats go, this is a new one to me. Most projects I
>>> interact with seem to use either mochijson or mochijson2. I'd love for
>>> there to be a canonical one though.
>>
>> All recent JSON projects follow that EEP as far as I know. If OTP gets
>> JSON support then your code will be working with the OTP implementation.
>> It's also less annoying to write than {struct, ...} because it's trying
>> (and not failing on me yet) to be a 1:1 match with Erlang types or when
>> not possible to give expected results.
>>
>> Personally I prefer jsx (https://github.com/talentdeficit/jsx) simply
>> because it's not a NIF and thus doesn't impact the scheduler. But your
>> needs and requirements may vary.
>
> It would be basically trivial to add {proplist()} support to
> mochijson2 as an addition to {struct, proplist()}. There's not much of
> a difference really, it's still wrapping a tuple around it but just
> without a tag. I'll have a look at that.
>
> -bob
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
An old version of Couchbeam accomplished that conversion thusly, if that
helps:
json_encode(V) ->
Handler =
fun({L}) when is_list(L) ->
{struct,L};
(Bad) ->
exit({json_encode, {bad_term, Bad}})
end,
(mochijson2:encoder([{handler, Handler}]))(V).
json_decode(V) ->
try (mochijson2:decoder([{object_hook, fun({struct,L}) -> {L} end}]))(V)
catch
_Type:_Error ->
throw({invalid_json,V})
end.
- --
James Aimonetti
Distributed Systems Engineer / DJ MC_
2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJOXDdOAAoJENc77s1OYoGg4D8H/2j63QYpyFRymqz62rhmlquf
5jCf9NoMpzYfSsJuC9fJhcvOtbpdr/Cx+62Y3GRDi0UMntdzvS0IwNmJvqH9uCer
WQ7gpPY+0tGxGfxDlMTnoBvgcfQM6bbjjMPFqN+dgDinVliAgwRhZpaJgd0hgvOm
g0Xb6ngK+pvueJV0cfTBsTFmMgI89rxJMb4yUFc0V54XctQTsAZhaxmP429jt0mP
e0YGQ0ZvAQaHM+CjRYuUlKHUrCUNmkXmgmjk54L9S0Ic5PZLpJMdpMWq6FWsMrIt
D7klF7x8E2v3w0gCHsPRS7n/XPV0Sp0sEuMz75Kifs5nsAuNUmLX5vG77sXuZ5s=
=QFs/
-----END PGP SIGNATURE-----
More information about the erlang-questions
mailing list