someapp / jsonerl Goto Github PK
View Code? Open in Web Editor NEWThis project forked from devinus/jsonerl
yet another but slightly different erlang <-> json encoder/decoder
This project forked from devinus/jsonerl
yet another but slightly different erlang <-> json encoder/decoder
It is modified version on Bob Ippolito's <[email protected]> mochijson2 module, one can find in excellent mochiweb, erlang webserver. Yet another JSON (RFC 4627) library for Erlang. jsonerl works with binaries as strings, arrays as lists (without an {array, _}) wrapper and it only knows how to decode UTF-8 (and ASCII). It has the following mapping: Erlang data type: => JavaScript data type: => Erlang data type: ----------------------------------------------------------------------------------------------- 1. atom true boolean true atom true 2. atom false boolean false atom false 3. atom undefined null atom undefined 4. any other atom string binary holding string 5. list array list 6. number number number 7. binary string binary 8. proptuple object proptuple ----------------------------------------------------------------------------------------------- Note: proptuple is result of passing proplist to list_to_atom bif ;) This is concept of mine to nicely model javascript object without a need of tagging structures on erlang side. Eg. JavaScript object { name: "Luc Besson", year_of_birth: 1959, city: "Paris", photo: "http://is.gd/3pYJF", movies: ["Taken","Bandidas","Taxi"] } results in { {<<"name">>, <<"Luc Besson">>}, {<<"year_of_birth">>, 1959}, {<<"city">>, <<"Paris">>}, {<<"photo">>, <<"http://is.gd/3pYJF">>}, {<<"movies">>, [<<"Taken">>,<<"Bandidas">>,<<"Taxi">>]} } ----------------------------------------------------------------------------------------------- Additionally there is utility macros delivered with jsonerl that helps turning erlang records to json and back. For example: -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: { name: "Luc Besson", year_of_birth: 1959, city: "Paris", photo: "http://is.gd/3pYJF", movies: ["Taken","Bandidas","Taxi"] } -record(man,{name,age}). Man1 = #man{name = "Petr", age = 45}, Man2 = #man{name = "Elton", age = 27 }, ListOfMans = [Man1,Man2], ListJson = ?list_record_to_json(man,ListOfMans) the resulting json will be: [ { name:"Petr", age:45 }, { name:"Elton", age:27 } ]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.