Left for archival purposes.

User avatar
By kmpm
#7175 a) I think nodeMCU is very much a part of this forum and it would be quite relevant to ask questions about it. Just look at the name of the forum section "Platforms -> LUA nodeMCU.com".[/list=]

b) Doing this in C (if you are now running in nodeMcu) would be a good thing since I think this would be a
thing that a lot of people are going to use for a lot of things[/*]
User avatar
By Fab85
#11423 I made some small changes to Bycocojackr42 script. It's still quike and dirty .

Code: Select allfunction fromJson(MSG)
   local hashMap = {}
   local i = 1
   local j = 1
   
   for val in string.gmatch(MSG,'"%w+":"%w+",') do
      hashMap[i] = {}
      val = string.gsub(val, '":"', " ")
      val = string.gsub(val, '"', "")
      val = string.gsub(val, ',', "")
     
      for sval in string.gmatch(val, "%S+") do         
          hashMap[i][j] = sval;
          j = j + 1
      end
      j = 1
      i = i+1
     
   end
   
   for val in string.gmatch(MSG,'"%w+":"%w+"}') do
      hashMap[i] = {}
      val = string.gsub(val, '":"', " ")
      val = string.gsub(val, '"', "")
      val = string.gsub(val, '}', "")
     
      for sval in string.gmatch(val, "%S+") do       
          hashMap[i][j] = sval;
          j = j + 1
      end
      j = 1
      i = i+1
   end
   return hashMap
end

function toJson(MAP)
   local outMsg = '{'
   local i = 1
   
   repeat
      outMsg = outMsg..'"'..map[i][1]..'":"'..map[i][2]..'",'
      i = i + 1
   until map[i] == nil
   
   return string.sub(outMsg,0,-2)..'}'
end
User avatar
By Michael Lee
#13249 This is supported in the latest firmware:

Code: Select alllocal json = require "cjson"
luaObject = json.decode("{\"json\": \"string\"}");
jsonString = json.encode(luaObject)