GameMaker (2.3)
Icon

JSON Struct

FrostyCat

You must be logged in to obtain assets

Description

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

  • Complete coverage of the JSON standard: Structs, arrays, numbers, strings, booleans, nulls
  • ZERO manual cleanup: No more ds_map_destroy()!
  • ZERO manual type marking: No more ds_map_add_*() or ds_list_mark_as*() for nested entries!
  • One-line utilities for loading and saving data
  • Encrypt data with ease using the built-in RC4 implementation or another algorithm of your choice
  • Encode plain and pretty-print JSON with equal ease

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).

Age Rating: 4+

Version

GMS2.3 - Version 1.1.0. Published September 16, 2021

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

  • Added jsons_encode_formatted and jsons_save_formatted for pretty-print JSON (#3).
Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait