Skip to main content
Version: bleeding-edge ๐Ÿฉธ

JSON

JSON library


๐ŸŽ’ Examplesโ€‹

(JSON.stringify) Stringifies a Lua table
local encoded_value = JSON.stringify({ 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" })
-- Outputs "[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]"
(JSON.parse) Parses a JSON string into a Lua table
local decoded_value = JSON.parse('[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]')
-- Outputs "the table { 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" }"
note

Note that custom classes (e.g. Vehicle, Character, Prop... etc) or functions are not supported to be stringified and will be nullified.

Structs (e.g. Vector, Rotator, Color... etc) are supported and will be parsed/stringified properly!

๐Ÿ—ฟ Static Functionsโ€‹

stringify: stringReturns a string representing value encoded in JSON
parse: anyReturns a value representing the decoded JSON string

stringifyModerateโ€‹

Returns a string representing value encoded in JSON

Functions and a table that references itself or one of its parent tables (cyclic table) cannot be encoded, they become null. Metatables are not encoded, only the table's own fields

local ret = JSON.stringify(value)
Parameters
NameTypeDescription
valuetablethe table that will become JSON
Returns
TypeDescription
stringthe table in JSON
Examples (1)
Stringifies a Lua table
local encoded_value = JSON.stringify({ 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" })
-- Outputs "[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]"

parseModerateโ€‹

Returns a value representing the decoded JSON string

local ret = JSON.parse(value)
Parameters
NameTypeDescription
valuestringthe JSON that will become a table
Returns
TypeDescription
anythe json in table
Examples (1)
Parses a JSON string into a Lua table
local decoded_value = JSON.parse('[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]')
-- Outputs "the table { 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" }"