Difference between revisions of "ToJSON"

From Multi Theft Auto: Wiki
Jump to: navigation, search
m (Seperate the feature line from what the function actually does.)
Line 2: Line 2:
{{Server client function}}
{{Server client function}}
{{New feature/item|3.0120|1.2||
{{New feature/item|3.0120|1.2||
Available client side in 1.2 and onwards
Available client side in 1.2 and onwards.

Revision as of 15:43, 14 September 2013

Available client side in 1.2 and onwards.

This function converts a single value (preferably a Lua table) into a JSON encoded string. You can use this to store the data and then load it again using fromJSON.


string toJSON ( var value )

Required Arguments

  • var: An argument of any type. Arguments that are elements will be stored as element IDs that are liable to change between sessions. As such, do not save elements across sessions as you will get unpredictable results.


Returns a JSON formatted string.


This example shows how you can encode an array. The string json should equal "[ { "1": "dogs", "mouse": "food", "cat": "hungry", "birds": 4 } ]" after executed.

local json = toJSON ( { "dogs", cat = "hungry", mouse = "food", birds = 4 } )


Minimum supported server 1.0
Minimum supported client 1.1.1-9.03316
Note: Using this function requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.0" client="1.1.1-9.03316" />

See Also