Thursday, 21 May 2015

JSON Parser in Erlang

Json parser created by erlang parsing tool lexx and yecc.

You have to download following erlang files

1.jsonParser.erl

2.jsonTokenGen.erl


simple way to use this parser like this

parse() ->
JSON = "
{
    \"geonames\": [
        {
            \"fcodeName\": \"capital of a political entity\",
            \"toponymName\": \"Mexico City\",
            \"countrycode\": \"MX\",
            \"fcl\": \"P\",
            \"fclName\": \"city, village,...\",
            \"name\": \"Mexiko-Stadt\",
            \"wikipedia\": \"en.wikipedia.org/wiki/Mexico_City\",
            \"lng\": -99.12766456604,
            \"fcode\": \"PPLC\",
            \"geonameId\": 3530597,
            \"lat\": 19.428472427036,
            \"population\": 12294193
        },
        {
            \"fcodeName\": \"capital of a political entity\",
            \"toponymName\": \"Beijing\",
            \"countrycode\": \"CN\",
            \"fcl\": \"P\",
            \"fclName\": \"city, village,...\",
            \"name\": \"Peking\",
            \"wikipedia\": \"en.wikipedia.org/wiki/Beijing\",
            \"lng\": 116.397228240967,
            \"fcode\": \"PPLC\",
            \"geonameId\": 1816670,
            \"lat\": 39.9074977414405,
            \"population\": 11716620
        }
    ]
}",
 {ok,Tokens,_} = jsonTokensGen:string(JSON),
  jsonParser:parse(Tokens).





No comments:

Post a Comment