Home > Uncategorized > erlang records <=> json

erlang records <=> json

September 18th, 2009 Daniello Leave a comment Go to comments

JSONERL is published.

It is simple tool for turning your erlang records into json and back.

Here is an example of the usage of jsonerl:

1
2
3
4
5
6
-include("jsonerl.hrl").
-record(artist, {name, year_of_birth, city, photo, movies}).
 
Artist = #artist{name = <<"Luc Besson">>, year_of_birth = 1959, city = <<"Paris">>, photo = <<"http://is.gd/3pYJF">>, movies = [<<"Taken">>,<<"Bandidas">>,<<"Taxi">>]},
Json = ?record_to_json(artist, Artist),
Artist = ?json_to_record(artist, Json).

the resulting json will be:

1
2
3
4
5
6
7
{
     name: "Luc Besson",
     year_of_birth: 1959,
     city: "Paris",
     photo: "http://is.gd/3pYJF",
     movies: ["Taken","Bandidas","Taxi"]
}

The code is available at github.

Categories: Uncategorized Tags: