alavrik / erlson

Erlang Simple Object Notation - dynamic name-value dictionary data type and syntax for Erlang
MIT License
81 stars 17 forks source link

Allow the Erlang empty tuple {} to represent an empty JSON struct. #6

Closed ewanmellor closed 11 years ago

ewanmellor commented 11 years ago

Without this, it is impossible to represent the JSON {"foo": {}}, because erlson turns an empty Erlang proplist into an empty JSON list.

alavrik commented 11 years ago

What do you think about supporting a more general form instead:

{json, iodata()}

I found this interface trick in mochijson2.erl and I like it. With this, you'd use {json, "{}"} instead of {}. It is still not a reversible representation, but it least it looks a little bit more general and less hacky. (A reversible representation would be nice, but unfortunately it is impossible to achieve without seriously changing Erlson internal representation).

ewanmellor commented 11 years ago

I think that a JSON escape would be useful for someone, no doubt. I like having {} work though -- what could be more graceful than {} mapping to {} !

alavrik commented 11 years ago

I still hope that Erlang will eventually adopt Erlson syntax for dynamic name-value dictionaries and get native support for JSON. If that ever happens, library-level hacks like using Erlang empty tuples to represent empty JSON objects would look bad. Not sure if it sounds like a good explanation but I tried :) Arguing about things like that is highly subjective after all...