I have been wanting to learn Erlang for quite some time, and last spring I bought the book Programming Erlang: Software for a Concurrent World to begin that journey. I read about 70% of the book and then life handed me some curve balls that suspended this great journey until recently. I rebooted my learning with Erlang by going through the book and doing the exercises at the end of each chapter. (Bonus: those exercises are under git if you are interested programming_erlang .) All was fine until I got to chapter five and learned of this disconnect…
Joe Armstrong describes three
BIFs, “built in function”, that ship with R17
of Erlang to convert JSON to maps
maps:to_json(Map) -> Bin
maps:from_json(Bin) -> Map
maps:safe_from_json(Bin) -> Map
Delving into that module from
erl tells a different tale unfortunately…
So, what gives?? Why the missing json methods? A bit of googling and you’ll find this:
I have not read Joes final book on the matter (several drafts though) .. and I’ve told him, twice I think, that there will not be any maps to json BIFs to in the maps module. It does not belong in the standard library.
This Bjorn seems like quite the hard-ass, with the power to lay down ultimate authority on these maters. Just who does he think he is?!?! Well it turns out he’s a dude who knows what he’s talking about. After a bit more digging into the issue it turns out that turning JSON into Erlang is not a strait solution. The keys can be represented in serveral different ways and there are already libraries out in the wild handling them in different ways.
How do you want your keys?
key ? Rather
than impose a single standard pick a library that works the way you need and
expect it to.