toJSON

From Bohemia Interactive Community
Jump to navigation Jump to search
Hover & click on the images for description
Only available in Development branch(es) until its release with Arma 3 patch v2.18.

Description

Description:
Serialise the passed data to JSON format.
Groups:
Strings

Syntax

Syntax:
toJSON data
Parameters:
data: can be one of:
  • HashMap: JSON object
  • Array: JSON array
  • Number: JSON number (float)
  • String: JSON string
  • Boolean: JSON bool (true/false, not 1/0)
  • nil: JSON null
    The nil value can only be passed as a member of Array/HashMap and cannot be passed directly as the command would simply not execute.
Return Value:
String - JSON result

Examples

Example 1:
private _result = toJSON ["this", "is", "an", "array"];
result:
["this","is","an","array"]
Example 2:
private _hashMap = createHashMap; _hashMap set ["bKey", true]; _hashMap set ["sKey", "Hello there"]; _hashMap set ["oKey", player]; _hashMap set ["nKey", 42]; _hashMap set ["hKey", ["key1", "key2", "yolo"] createHashMapFromArray ["General Kenobi", true, "Hello it's me"]]; toJSON _hashMap;

result:

{"bKey":true,"sKey":"Hello there","oKey":null,"nkey":42,hKey:{"key1":"General Kenobi","key2":true,"yolo":"Hello it's me"}}
Example 4:
private _jsonPlayer = toJSON player; // empty string - Object is not supported

Additional Information

See also:
fromJSON toString str

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note