Sunday, October 9, 2011

Erlang JSON

I've got a Erlang web service (built on Spooky) which I want to return JSON. How hard could that be?

The problem is a multitude of half-assed implementations.

What seems to work is mochijson2, which comes as part of mochiweb, but only the version from Mochi, not the Basho branch.

I have an Erlang structure that looks like this:
[{"colin",[3,2,1]},{"dave",[4,3,2]}]

That's an array with two tuples. Shouldn't be rocket science, but apparently what they really want is:
[{struct,[{<<"colin">>,[1,2,3]}]},{struct,[{<<"dave">>,[4,3,2]}]}]
or some shit. Really? If I have to munge it into that format, I might as well just encode it myself.

P.S. After going a few rounds with mochijson2, I ended up just encoding it myself.

No comments:

Post a Comment