jsonHelper.lua utility file - VanaDev/Vana GitHub Wiki

Table of Contents

jsonHelper.lua

Category: Utility Lua-Based Scripts

serialize_err

Type: number

Notes: Used as a return value from the serialize functions to indicate an error has occurred. The result will be the error message instead of serialized/deserialized data in this case.

serialize_ok

Type: number

Notes: Used as a return value from the serialize functions to indicate no error has occurred. The result will be serialized/deserialized data in this case.

serialize

Return(s):

  • serializeResultCode: number
  • serializeResult: string
Argument(s):
  • value: any
Notes: Serializes the specified value into a string. number, table, string, boolean and nil are all supported types.

Usage:

 val = { ["key"] = 123, ["value"] = 456 };
 result, data = serialize(val);
 if result == serialize_err then
 	print("Error: " .. data);
 else
 	-- Here, data should be a string roughly equivalent to {key: 123, value: 456}
 end

deserialize

Return(s):

  • serializeResultCode: number
  • serializeResult: string
Argument(s):
  • value: string
Notes: Deserializes the specified string into a Lua value. number, table, string, boolean and nil are all supported types.

Usage:

 json = "{key: 123, value: 456}";
 result, data = deserialize(val);
 if result == serialize_err then
 	print("Error: " .. data);
 else
 	-- Here, data should be a value roughly equivalent to { ["key"] = 123, ["value"] = 456 }
 end
⚠️ **GitHub.com Fallback** ⚠️