Closed ewanmellor closed 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).
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 {}
!
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...
Without this, it is impossible to represent the JSON {"foo": {}}, because erlson turns an empty Erlang proplist into an empty JSON list.