ll.Table2Json and ll.Json2Table
WolfGang Senizen
Functions to convert from lua table to json string would be amazing.
ESPECIALLY if they can handle vector uuid and quaternion casting correctly.
ll.Table2Json
Recursively convert a table to json.
Some values in a table may not be convertible like functions, and should probably be skipped.
local data = {1,2,{a="b"},{c={d="e"}}}
local json = ll.Table2Json(data)
ll.OwnerSay(json)
Would output something similar to
[1,2,{"a":"b"},{"c":{"d":"e"}}]
ll.Json2Table
Convert a json string to a table.
local json = '[1,2,{"a":"b"},{"c":{"d":"e"}}]'
local data = ll.Json2Table(json)
Would create a table similar to
{1,2,{a="b"},{c={d="e"}}}
Casting of vector quaternions uuids booleans etc
It would solve ALLOT of problems if these methods handled casting of certain datatypes for users.
Avoid lsl's
(vector)llList2String(list,0)
problemP.S.
I have made a "crappy" lua function that mocks ll.Table2Json mostly for debugging purposes
Log In
Kadah Coba
A couple pure lua JSON libs I found
A c implementation
SamanthaTekcat Resident
It would be also helpful to have Functions for Tables similar to the llJsonSetValue and llJsonGetValue functions in Lua
WolfGang Senizen
Working with SamanthaTekcat Resident yesterday
We came up with
setTableVal
local function setTableVal(tab,path,val)
for k,v in pairs(path) do
if k == #path then break end
if type(tab[v]) == nil then tab[v] = {}
tab = tab[v]
if type(tab) ~= "table" then return false end
end
tab[path[#path]] = val
end
And
getTableVal
local function getTableVal(tab,path)
for k,v in pairs(path) do
tab = tab[v]
if tab == nil then return nil end
end
return tab
end
As helper lua functions for those
They aren't identical as they modify the table in place, and don't quite support the
JSON_DELETE
type of functionality, you can pass nil
but that's a bit different