Topi Posted June 2, 2022 Share Posted June 2, 2022 How i can enconde lua table to JSON ? Link to comment Share on other sites More sharing options...
MarioRossi93i Posted June 2, 2022 Share Posted June 2, 2022 https://github.com/Egor-Skriptunoff/json4lua/blob/master/json.lua Link to comment Share on other sites More sharing options...
MAARS Posted June 3, 2022 Share Posted June 3, 2022 You can even use this portable module made by @TisNquyen local json = { decode = function(js) local l = "return " .. js:gsub('("[^"]-"):','[%1]=') local tbl = load(l)() return tbl end, encode = function (tbl) return (dump or tostring)(tbl) :gsub("%['(%w+)'%] = ([%{'%w])", "\"%1\": %2") :gsub("%-%- table%b()", "") :gsub(": '(.-)'", ": \"%1\"") :gsub("([\"%w]),(%s*%})", "%1%2") end } -- // TEST // -- local js=[[ { "data": { "user": { "username": "username", "type": "TYPE" } }, "passport": { "user": "uuid" }, } ]] print("JSON : ", js) local tbl = json.decode(js) print("json.decode :", tbl) print("json.encode :", json.encode(tbl)) -- Lua json for gg & andlua (simple) -- join chat : @tisgroupchat -- channel : @tisnquyen -- final boss : @tis_nquyen Link to comment Share on other sites More sharing options...
Question
Topi
How i can enconde lua table to JSON ?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.