{"name":"toJSON","title":"toJSON","type":"command","url":"https://community.bistudio.com/wiki/toJSON","revid":379521,"updated":"2026-10-31T00:29:49Z","groups":["Strings"],"status":"ok","games":{"arma3":"2.18"},"since":"arma3 2.18","arma3_since":"2.18","description":"Converts data to [JSON](https://en.wikipedia.org/wiki/JSON).","syntaxes":[{"syntax":"toJSON data","params":[{"name":"data","type":"Boolean, Number, String, Array, HashMap or nil","description":"Only certain Data Types are supported:\n\n- Boolean - serialized as JSON boolean\n- Number - serialized as JSON number (floating-point)\n- String - serialized as JSON string\n- Array - Serialized as JSON array. Unsupported elements (e.g. Objects) are converted to JSON null.\n- HashMap - Serialized as JSON object. Only String keys are supported, other keys are ignored. Unsupported values (e.g. Objects) are converted to JSON null.\n- nil - serialized as JSON null\n\n  > [!IMPORTANT]\n  > The nil value can only be passed as a member of an Array or HashMap. It cannot be passed directly as the command would simply not execute.","type_expr":"Boolean | Number | String | Array | HashMap | Nothing"}],"returns":{"type":"String","type_expr":"String","description":"JSON string"},"form":"unary","right":{"text":"data"}}],"examples":[{"text":"```sqf\nprivate _result = toJSON [\"this\", \"is\", \"an\", \"array\"];\n```\n\nResult:\n\n```json\n[\"this\",\"is\",\"an\",\"array\"]\n```","code":["private _result = toJSON [\"this\", \"is\", \"an\", \"array\"];"]},{"text":"```sqf\nprivate _hashMap = createHashMap;\n_hashMap set [\"bKey\", true];\n_hashMap set [\"sKey\", \"Hello there\"];\n_hashMap set [\"oKey\", player];\n_hashMap set [\"nKey\", 42];\n_hashMap set [\"hKey\", [\"key1\", \"key2\", \"yolo\"] createHashMapFromArray [\"General Kenobi\", true, \"Hello it's me\"]];\ntoJSON _hashMap;\n```\n\nResult (formatted for readability):\n\n```json\n{\n    \"bKey\": true,\n    \"sKey\": \"Hello there\",\n    \"oKey\": null,\n    \"nkey\": 42,\n    \"hKey\": {\n        \"key1\": \"General Kenobi\",\n        \"key2\": true,\n        \"yolo\": \"Hello it's me\"\n    }\n}\n```","code":["private _hashMap = createHashMap;\n_hashMap set [\"bKey\", true];\n_hashMap set [\"sKey\", \"Hello there\"];\n_hashMap set [\"oKey\", player];\n_hashMap set [\"nKey\", 42];\n_hashMap set [\"hKey\", [\"key1\", \"key2\", \"yolo\"] createHashMapFromArray [\"General Kenobi\", true, \"Hello it's me\"]];\ntoJSON _hashMap;"]},{"code":["private _jsonPlayer = toJSON player; // empty string - Object is not supported"]}],"see_also":["fromJSON","toString","str"]}