JSONEncode doesn't encode special stuff like Vector3, what could be done about that?

JSONEncode doesn’t encode special stuff like Vector3, what could be done about that?

Let’s say you have a table and have a Vector3.new(1,1,1) inside of it and then use JSONEncode.

There might be other things that it doesn’t encode too.

You can convert the vector3 to table then encode it.

--convery vector3 to table
local vector = Vector3.new(0,0,0)
local encoded
encoded = {vector.X,vector.Y,vector.Z}
encoded = game.HttpsService:JSONEncode(encoded)
1 Like

Convert it into an format which can be encoded into a JSON string.

local Http = game:GetService("HttpService")
local Vector = Vector3.new(1, 1, 1)
local TableVector = {Vector.X, Vector.Y, Vector.Z}
local Encoded = Http:JSONEncode(TableVector)
1 Like

Just send the x, y, x as a table and decompile it the same way

yeah, though Vector3 is not the only thing, I don’t know what other things may cause issues.

Maybe checking if something is not nil and if it becomes nil, but uhhh

You can also convert other things using this methods depending on arguments.

Have to functions, Compile and decompile

Compiling:

local function compile(vector)
    return game.HttpsService:JSONEncode({vector.X,vector.Y,vector.Z})
end

Decompiling:

local function decompile(json)
   local table = game.HttpsService:JSONDecode(json)
   return Vector3.new(table[1],table[2],table[3])
end

No, compiling would be :JSONEncode, and decompiling would be :JSONDecode. And also in the JSONEncode it needs to be a table so :JSONEncode({vector.X,vector.Y,vector.Z})

Also its not HttpsService its HttpService

1 Like