Last active
April 23, 2021 16:26
-
-
Save otavionetoca/cf52e020c54bdd8ddeecbb6ac702f461 to your computer and use it in GitHub Desktop.
TableToStringifiedJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TableToStringifiedJSON(table) | |
if type(table) ~= "table" then | |
Package:Log("[UTILS] Param expected as type table") | |
return | |
end | |
local stringified = "" | |
for k, _ in pairs(table) do | |
if type(k) == "table" then | |
TableToStringifiedJSON(k) | |
end | |
stringified = stringified .. "{\"" .. tostring(k) .. "\":{" | |
for k2, v2 in pairs(table[k]) do | |
local value | |
if type(v2) == "string" then | |
value = "\"" .. tostring(v2) .. "\"" | |
else | |
value = tostring(v2) | |
end | |
stringified = stringified .. "\"" .. tostring(k2) .. "\":" .. value .. "," | |
end | |
end | |
-- Remove last comma so JS is able to parse it | |
return stringified:sub(0, #stringified - 1) .. "}}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GENIUS SAVED MY LIFE