Skip to content

JSON

The static global JSON class provides the ability to encode/decode data into JSON strings. This is largely used by the onSave() event function, but has other potential applications as well. The JSON class can be used on any String, Int, Float or Table. You call these functions like this: JSON.encode(...).

Warning

This class does not work with Object references. Use the Object's GUID instead.

Function Summary

Function Name Description Return  
decode( json_string) Value obtained from the encoded string. Can return a number, string or Table.
encode( data) Encodes data from a number, string or Table into a JSON string.
encode_pretty( data) Same as encode(...) but this version is slightly less efficient but is easier to read.

Function Details

decode(...)

Value obtained from the encoded string. Can return a number, string or Table.

decode(json_string)

  • json_string: A String that is decoded, generally created by encode(...) or encode_pretty(...).
coded = JSON.encode("Test")
print(coded) --Prints "Test"
decoded = JSON.decode(coded)
print(decoded) --Prints Test

encode(...)

Encodes data from a number, string or Table into a JSON string.

encode(data)

  • data: A Var, either String, Int, Float or Table, to encode as a string.

encode_pretty(...)

Encodes data from a number, string or Table into a JSON string. This version is slightly less efficient but is easier to read.

encode_pretty(data)

  • data: A Var, either String, Int, Float or Table, to encode as a string.