Overview
JSON Struct is a complete, cleanup-free replacement for GMS 2's built-in JSON functions. Encode and decode JSON as native structs and arrays, load and save them in one take, and even encrypt them!
Features
ds_map_destroy()
!ds_map_add_*()
or ds_list_mark_as*()
for nested entries!Documentation
See the Wiki section on the official GitHub repository.
Examples
Saving JSON data:
jsons_save("example.json", {
messages: ["Hello World!", "Goodbye World!"]
});
Loading JSON data:
global.messages = jsons_load("example.json");
Decoding JSON strings:
var json_str = @'{"messages":["Hello World!", "Goodbye World!"]}';
//...
var json_data = jsons_decode(json_str);
show_message(json_data.messages[0]); //Hello World!
End User Licence Agreement (EULA).
Encoding and saving pretty-print JSON is now possible thanks to contributions by Aivan Fouren.
Required Changes
If you are upgrading from JSON Struct v1.0.0, please add these macros to Libraries_config/JsonStruct/__JSONS_CONFIG__
or import the version that comes with the asset package:
//Specify the default formatting for jsons_encode_formatted and jsons_save_formatted
//You can specify fixed values or expressions containing global variables for these
#macro JSONS_FORMATTED_COMMA ", "
#macro JSONS_FORMATTED_COLON ": "
#macro JSONS_FORMATTED_INDENT "\t"
#macro JSONS_FORMATTED_MAX_DEPTH infinity
New Features
jsons_encode_formatted
and jsons_save_formatted
for pretty-print JSON (#3).