For common data types some optimisations could be done. For example for Color3
s each compontent could be bitpacked (Or converted to a HEX string, both would take the same amount of bytes in JSON).
Other things to make the JSON format easier to store is instead of using direct property names like:
"ClassName": THEDATA
"Name": THEDATA
"Size": THEDATA
They could instead be HEX encoded indexes to an array table where the elements are property names. Like the indexes for instances would be:
"1": THEDATA
"5": THEDATA
-
"4F": THEDATA
And the table where the indexes are stored would be like:
[
"ClassName",
SOME OTHER PROPERTY NAMES HERE
"Name",
SOME OTHER PROPERTY NAMES HERE
"Size"
]
This would make quite a lot of improvements in storage size but still keep the ease of implementation which JSON provides.
Let’s say we wan’t to deserialise or serialise models in Roblox Luau or a web application with javascript. A JSON implementation is by far the easiest to implement and upkeep and it still provides relatively good
A lot of people use XML instead of the binary format due to it’s ease of use, so a JSON format would definetly be in need.
Deserialisation of a JSON based format in Lua code would be as easy as doing
local typeHandlers = {
-- The type handlers
}
local function doStuff(data, parent, indexReferences, typeReferences)
local object = Instance.new(data[1])
for k, v in pairs(data[2]) do
local rawK = indexReferences[k]
if typeReferences[rawK] then
object[rawK] = typeHandlers[typeReferences[rawK]](v)
else
object[rawK] = v
end
end
for _, v in ipairs(data[3]) do
doStuff(v, object, indexReferences, typeReferences)
end
end
local tbl = game:GetService("HttpService"):JSONDecode(THEDATA)
doStuff(tbl[1], nil, tbl[2], tbl[3]).Parent = workspace
Here would be an example JSON serialised model (just an example):
[["Model",{"1":"ModelWithAPart","2":[0,0,0,0,0,0]},[["Part",{"2":[10,0.4523534,5,0,0,0],"3":[10,50,20],"4":10551051},[]]]],["Name","CFrame","Size","Color3"],{"CFrame":"CFrame","Size":"Vector3","Color":"Color3"}]
(The property indexes are HEX instead of numbers so they save some space for models with a lot of properties. Alternatively the indexes could be raw bytes (0-255 meaning all string characters) making them use even less character space)