-->
Page 1 of 2

JSON Parser

PostPosted: Fri Jan 09, 2015 1:34 pm
by cocojackr42
I'd like to access the including JSON parser (https://github.com/nodemcu/nodemcu-firm ... sonparse.c) via LUA calls.
Because I am too stupid to set up the compiler and ide (best would be with eclipse), make them accessible through LUA calls please :).

Re: JSON Parser

PostPosted: Fri Jan 09, 2015 3:40 pm
by mog
I think you could try reaching out to the authors of https://github.com/nodemcu/nodemcu-firmware

Re: JSON Parser

PostPosted: Fri Jan 09, 2015 3:45 pm
by mog
Duh, I thought that nodemcu project is separate from this forum :)

Maybe you could try parsing json in LUA like in http://regex.info/blog/lua/json

Re: JSON Parser

PostPosted: Fri Jan 09, 2015 3:53 pm
by cocojackr42
I've already tried to work with this skript, but it seems the esp isnt capable of this. (restarts after dofile)

I thought this category of this forum is just for this...

**edit

Now I wrote some regex-based "parser" for json-maps,.. That works at least. Maybe someone with a little bit more "lua" skill writes a good one usable by the esp.

Code: Select allfunction fromJson(MSG)
   local hashMap = {}
   for k,v in string.gmatch(MSG,'"(%w+)":"(%w+)",') do
      hashMap[k] = v;
   end
   for k,v in string.gmatch(MSG,'"(%w+)":"(%w+)"}') do
      hashMap[k] = v;
   end
   return hashMap
end


function toJson(MAP)
   local outMsg = "{"
   for k,v in pairs(MAP) do
      outMsg = outMsg..'"'..k..'":"'..v..'",'
   end
   return string.sub(outMsg,0,-2)..'}'
end