spacer.png, 0 kB
Erlang JSON encoding & decoding

JSON has become one of the most used standard notations for data transport. How to use JSON in Erlang though? There is no standard library that does this. At work, we use Mochiweb (Erlang HTTP toolkit) and then specifically the module mochijson2.erl This module works great, but we made a few small patches to it (improved UTF8 handling and better tuple support). I'll try to post those patches at a later time.

  • %% @author Bob Ippolito
  • %% @copyright 2007 Mochi Media, Inc.
  • %% @doc Yet another JSON (RFC 4627) library for Erlang. mochijson2 works
  • %% with binaries as strings, arrays as lists (without an {array, _})
  • %% wrapper and it only knows how to decode UTF-8 (and ASCII).


Just grab the Mochiweb source tree, add it to your project and include the mochijson2.erl file. You can then simply encode and decode like this:

 
JsonEncoded = encode(E).
Decoded = encode(JsonEncoded).
 
Mochiweb is useful, but it's not the fastest option. We now don't use Mochiweb anymore, but a C-based linkedin driver based on Yajl. It's way faster than any Erlang method. It's based on eep0018

Comments
Add New
+/-
Write comment
Name:
Email:
 
Website:
Title:
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Sunday, 21 November 2010 )
 
Next >
spacer.png, 0 kB
rightborder
© 2006-2011 StartInChina.com - News and tips from Shenzhen, China