Arma 3 Scripting

toJSON

  • Arma 3 v2.18

Command · Markdown · JSON · original wiki page

Description

Converts data to JSON.

Syntax

toJSON data

Parameters:

Returns: String - JSON string

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 (formatted for readability):

{
    "bKey": true,
    "sKey": "Hello there",
    "oKey": null,
    "nkey": 42,
    "hKey": {
        "key1": "General Kenobi",
        "key2": true,
        "yolo": "Hello it's me"
    }
}

Example 3

private _jsonPlayer = toJSON player; // empty string - [[Object]] is not supported

See also

fromJSON · toString · str