Jump to content


Photo

JSOnion: The stink-free way to handle nested JSON!


  • Please log in to reply
36 replies to this topic

#1 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 01 January 2013 - 03:22 AM

JSOnion v1.1.0

The original lightweight JSON library for 8.1 and Studio 1.x

Download
Compatible with: 8.1, Studio 1.x
Download: GitHub

Plugins

Archived Versions

Spoiler


Introduction
JSOnion is a full-featured alternative for the built-in json_encode() and json_decode() functions. It has complete support for all JSON data types and allow easy one-line access to even deeply nested JSON structures.

 

Features

  • Easy to use, fast and extensively tested
  • Full documentation with annotated examples
  • Encodes minified JSON with arbitrary nesting depths
  • Decodes JSON with arbitrary nesting depths, cleanly formatted or not
  • One-line access to entries from any part of a decoded JSON structure, even deeply nested entries
  • Compatible with real-valued, integer, Boolean, null, string, map and list data types
  • Fully recursive cleanup routine that cleans up even nested structures inside with no fuss

 

The Secret to JSOnion
The problem with json_encode() is that lists, maps and Booleans are all represented by numeric values, sharing a type with actual real values:

{"list":0, "three":3, "test":“string”, "bool":0}

It is impossible in code to tell that the 0 is not just any plain old real number, or in fact a list/map handle or a Boolean value. But by prefixing it with “l” (l for list) or "b" (b for Boolean) and the string with “s” (s for string), we can get the following:

{"list":"l0", "three":3, “test”:”sstring”, "bool":"bfalse"}

The prefix artificially adds a type to our numeric values without any further additions to GML!
 
 
Known Issues

  • GM:Studio 1.2.1279 and 1.99.65 only: There are bugs in the way that HTML5-based platforms handle map keys in these versions that will cause corrupted encodes. Please do not use JSOnion with these versions if you intend on exporting to HTML5, Windows 8 JS or Tizen JS.
  • GM:Studio 1.1.1058 and 1.1.1076 only: There are bugs in the way YYC handles certain reals and strings in these versions that will cause corrupted encodes. You can resolve this by upgrading GM:Studio to 1.1.1086 or later and JSOnion to 1.0.0d.

If you have any comments, questions or suggestions for expansion, feel free to post here. Enjoy!


Edited by GameGeisha, 09 February 2016 - 03:19 AM.

  • 8
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#2 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 07 January 2013 - 04:24 AM

I have just addressed a crash in JSOnion v1.0.0 that occurs when trying to encode boolean values in maps. If you have v1.0.0, please delete the following group of lines in jso_encode_map() to fix the crash:
case jso_type_integer:
  s += jso_encode_integer(jso_map_get(argument0, k));
break;
Alternatively, you can also download v1.0.0a, deleting the imported scripts and then re-importing. Skip the constants if you are using v1.0.0, as you already have them.

Also, a quick preview of what is in development for v1.0.1:
  • Support for the null type!
  • "Path-flavoured" versions of lookup functions: ex. jso_list_lookup(list, 0, "name", "first") ==> jso_list_lookup_path(list, "0\name\first")
  • GEX Extension availability --- even simpler installation!

GameGeisha
  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#3 stephenhonor

stephenhonor

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 09 January 2013 - 11:08 PM

Really like the scripts you've developed, one thing I would like to ask about though relates to having lists within maps.

Example:
{
  "params":
  {
    "characters":
    [
      {"id":1,"name":"Dave"},
      {"id":2,"name":"Bob"}
    ]
  }
}

This is obviously something that can happen normally but does not seem to be handled very well in GM.. at least I am unable to figure out how.

SH

Edit: I changed the json string to be easier to read.

Edited Again: It is actually possible to get the name of characters using the following and print the name of Dave.

show_message(jso_map_get(jso_list_get(jso_map_get(jso_map_get(map,"params"),"characters"),0),"name"));

Edited by stephenhonor, 11 January 2013 - 09:25 PM.

  • 0

#4 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 12 January 2013 - 04:45 AM

Really like the scripts you've developed, one thing I would like to ask about though relates to having lists within maps.

Example:

{
  "params":
  {
    "characters":
    [
      {"id":1,"name":"Dave"},
      {"id":2,"name":"Bob"}
    ]
  }
}

This is obviously something that can happen normally but does not seem to be handled very well in GM.. at least I am unable to figure out how.

SH

Edit: I changed the json string to be easier to read.

Edited Again: It is actually possible to get the name of characters using the following and print the name of Dave.

show_message(jso_map_get(jso_list_get(jso_map_get(jso_map_get(map,"params"),"characters"),0),"name"));

I'm glad you figured it out yourself, but for your reference, there is a cleaner way to traverse nested JSON than that: jso_map_lookup().
var json, json_data, dave;
json = '{"params":{"characters":[{"id":1,"name":"Dave"},{"id":2,"name":"Bob"}]}}';
json_data = jso_decode_map(json);
dave = jso_map_lookup(json_data, "params", "characters", 0, "name");
jso_cleanup_map(json_data);

GameGeisha

Edited by GameGeisha, 12 January 2013 - 04:46 AM.

  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#5 stanchat

stanchat

    GMC Member

  • GMC Member
  • 68 posts

Posted 04 February 2013 - 10:13 PM

I recently upgraded to 1.1.805 and now the JSOnion is throwing the following errors.

Error : gml_Script_jso_encode_string(16) : Case argument should be a constant
Error : gml_Script_jso_encode_string(19) : Case argument should be a constant
Error : gml_Script_jso_encode_string(22) : Case argument should be a constant
Error : gml_Script_jso_encode_string(25) : Case argument should be a constant
Error : gml_Script_jso_encode_string(28) : Case argument should be a constant

===============================================================

{
    /**
    jso_encode_string(str): Return a JSON-encoded version of string <str>.
    */
    //Iteratively reconstruct the string
    var i, l, s, c;
    s = "";
    l = string_length(argument0);
    for (i=1; i<=l; i+=1) {
        //Replace escape characters
        c = string_char_at(argument0, i);
        switch (c) {
            case '"': case "\": case "/": //Double quotes, backslashes and slashes
                s += "\" + c;
            break;
            case chr(8): //Backspace
                s += "\b";
            break;
            case chr(12): //Form feed
                s += "\f";
            break;
            case chr(10): //New line
                s += "\n";
            break;
            case chr(13): //Carriage return
                s += "\r";
            break;
            case chr(9): //Horizontal tab
                s += "\t";
            break;
            default: //Not an escape character
                s += c;
            break;
        }
    }
    //Add quotes
    return '"' + s + '"';
}


  • 0

#6 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 05 February 2013 - 01:11 AM

I recently upgraded to 1.1.805 and now the JSOnion is throwing the following errors.

Error : gml_Script_jso_encode_string(16) : Case argument should be a constant
Error : gml_Script_jso_encode_string(19) : Case argument should be a constant
Error : gml_Script_jso_encode_string(22) : Case argument should be a constant
Error : gml_Script_jso_encode_string(25) : Case argument should be a constant
Error : gml_Script_jso_encode_string(28) : Case argument should be a constant

This crash is caused by a recent change in GMS v1.1.805, which introduced a ban on non-constant expressions in case statements. Even though these cases clearly have constant values, the algorithm employed in the current version of GM failed to notice it. I have uploaded a new version 1.0.0b to address this problem.

For those who already have JSOnion installed and are affected by this change, just replace your jso_encode_string() with this:
{
    /**
    jso_encode_string(str): Return a JSON-encoded version of string <str>.
    */
    
    //Iteratively reconstruct the string
    var i, l, s, c;
    s = "";
    l = string_length(argument0);
    for (i=1; i<=l; i+=1) {
        //Replace escape characters
        c = string_char_at(argument0, i);
        switch (ord(c)) {
            case 34: case 92: case 47: //Double quotes, backslashes and slashes
                s += "\" + c;
            break;
            case 8: //Backspace
                s += "\b";
            break;
            case 12: //Form feed
                s += "\f";
            break;
            case 10: //New line
                s += "\n";
            break;
            case 13: //Carriage return
                s += "\r";
            break;
            case 9: //Horizontal tab
                s += "\t";
            break;
            default: //Not an escape character
                s += c;
            break;
        }
    }

    //Add quotes
    return '"' + s + '"';
}

GameGeisha
  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#7 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 08 February 2013 - 09:27 PM

Ok so I'm just now finding this... GameGeisha you are officially on my Christmas list!
  • 0

#8 Indecom4000

Indecom4000

    GMC Member

  • GMC Member
  • 1636 posts
  • Version:GM:Studio

Posted 27 February 2013 - 11:30 AM

I just stumbled across this while trying to figure out how to easily store and read from a hierarchy of data stored in a huge list of nested ds_lists and ds_maps. This seems to be the perfect solution for me, i dont even care about the encoding part, just the whole nested data is amazing!

Just out of curiousity, does decode work with the xml format as well as json?

Edited by Indecom4000, 27 February 2013 - 11:59 PM.

  • 0

LD-Logo-sml.png


#9 cklester

cklester

    GMC Member

  • GMC Member
  • 175 posts
  • Version:GM:Studio

Posted 04 July 2013 - 06:14 AM

Getting this back as a string from a provider:

 

{"data":[]}
 
How do I parse that with JSOnion? I'm using
 
json_data = jso_decode_map(res);
data = jso_map_lookup(json_data, "data");

It's returning an empty string to data. Is that expected behavior?

 

 


Edited by cklester, 04 July 2013 - 06:14 AM.

  • 0

#10 cklester

cklester

    GMC Member

  • GMC Member
  • 175 posts
  • Version:GM:Studio

Posted 07 July 2013 - 06:47 PM

Calling on @GameGeisha for expert help... please, check your email.

 

Thank you in advance! :-)


  • 0

#11 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 08 July 2013 - 07:54 PM

@cklester:

 

You can accomplish this lookup by doing it in 2 parts:

  1. Determine which index from the data array contains a record with key "scoreBoardName" and value "Practice 1-Crawler".
  2. Reuse that index to find the value in the key "scoreValue".
//Decode
//This assumes that the incoming json has been stored in json
var json_data = jso_decode_map(json);

//Loop through the data array to find "Practice 1-Crawler"
var json_data_entries = jso_map_lookup(json_data, "data");
var i = 0, l = ds_list_size(json_data_entries);
for (i=0; i<l; i++) {
	var score_board_name = jso_list_lookup(json_data_entries, i, "scoreBoardName");
	if (score_board_name == "Practice 1-Crawler") {
		break;
	}
}

//Reuse the index to find score value
practice_score[0] = jso_list_lookup(json_data_entries, i, "scoreValue");

//Done
jso_cleanup_map(json_data);

GameGeisha


  • 1
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#12 cklester

cklester

    GMC Member

  • GMC Member
  • 175 posts
  • Version:GM:Studio

Posted 08 July 2013 - 07:56 PM

@GameGeisha,

 

Lots of good info in that post!

 

I'll be back on this project tonight. Currently, I've actually got it working a bit differently, but your way is no doubt better and official. :-)

 

Thanks!!!


  • 0

#13 cklester

cklester

    GMC Member

  • GMC Member
  • 175 posts
  • Version:GM:Studio

Posted 15 July 2013 - 04:47 PM

@GameGeisha, could you provide (or let me know if this already exists) an optional function for "pretty printing" the JSON (you know, formatted nicely with line feeds, indented child elements, etc...)? As a human, I'd like to be able to quickly parse the data myself, if necessary.

 

Thank you!


  • 0

#14 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 15 July 2013 - 05:28 PM

@GameGeisha, could you provide (or let me know if this already exists) an optional function for "pretty printing" the JSON (you know, formatted nicely with line feeds, indented child elements, etc...)? As a human, I'd like to be able to quickly parse the data myself, if necessary.

 

Thank you!

 

There are currently no functions in JSOnion that encode to an indented format, but I can add this into the to-do list for v1.1.

 

In the meanwhile, you can look into using external JSON formatters or Notepad++ plugins.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#15 cklester

cklester

    GMC Member

  • GMC Member
  • 175 posts
  • Version:GM:Studio

Posted 15 July 2013 - 06:53 PM

OK, thanks for that info!


  • 0

#16 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 01 August 2013 - 12:10 AM

I have released a new version 1.0.0c to address compiler errors related to argument counts in GMS 1.1.1058 and 1.1.1076.
 
If you already have v1.0.0b, you can manually patch your JSOnion library by replacing argument0 with argument[0] in the following scripts:

  • jso_map_check
  • jso_list_check
  • jso_map_lookup
  • jso_map_lookup_type
  • jso_list_lookup
  • jso_list_lookup_type

Many thanks to mavb15 and phocker for bringing this issue to my attention.

 

GameGeisha


Edited by GameGeisha, 01 August 2013 - 12:15 AM.

  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#17 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 10 August 2013 - 03:38 AM

I have released a new version 1.0.0d to address YYC runtime errors with numeric conversion. Note that you must upgrade to GMS 1.1.1086 or later.
 
If you already have 1.0.0c and have problems with YYC, you can manually patch your JSOnion by replacing the following scripts:
 
__jso_gmt_numtostr
Spoiler

 
_assert_debug_value (optional --- do this only if you have the test suite imported)
Spoiler

 
GameGeisha
  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#18 Serena

Serena

    GMC Member

  • GMC Member
  • 77 posts
  • Version:GM:Studio

Posted 19 September 2013 - 02:57 AM

I really want to give this a try.  I have a question though... I have some large (50-200kb) JSON  files several levels deep, I'd like to bring them into my game.  Is this something I can do with this system?


  • 0

My webcomic: http://angelfoodcomic.com

http://seremeres.com

Proud user of Game Maker since 2002!


#19 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 19 September 2013 - 09:30 PM

I really want to give this a try.  I have a question though... I have some large (50-200kb) JSON  files several levels deep, I'd like to bring them into my game.  Is this something I can do with this system?

 

JSOnion is designed to parse JSON strings of arbitrary lengths, but keep in mind that there is a 100000-character limit on GML strings. If your JSON string grows beyond this limit, there is a risk that what you pass into JSOnion could be cut off in the middle. As a start, minifying your JSON files (removing indents, carriage returns, etc.) can greatly reduce their size while retaining their machine-readability.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#20 Serena

Serena

    GMC Member

  • GMC Member
  • 77 posts
  • Version:GM:Studio

Posted 20 September 2013 - 08:32 PM

Looks like I may have to come up with some sort of dynamic solution to reduce the string size before it gets passed into the script.  Because of the way JSON is structured it obviously needs the entire string, hmmm...


  • 0

My webcomic: http://angelfoodcomic.com

http://seremeres.com

Proud user of Game Maker since 2002!


#21 Krzycho

Krzycho

    GMC Member

  • New Member
  • 16 posts
  • Version:GM:Studio

Posted 24 December 2013 - 01:58 AM

Oh my god! I was messing around with GM:S's JSON default api for a couple of hours now, trying to parse some nested file. No success...

After downloading your's I came with the proper output after 30sec of code writing! You made my day sir! =D

 

Happy holidays to you! Ho, ho, ho!


  • 0

#22 iconmaster

iconmaster

    GMC Member

  • GMC Member
  • 22 posts
  • Version:GM8.1

Posted 11 January 2014 - 09:05 PM

I needed a way to save all of my complex data to file (GM8.1's default saving mechanism is, to put it one way, entirely bogus), and something like XML or JSON encoding came to mind. Not wanting to parse these complex strings myself, I went around looking for something to do this. It looks like I'm using JSON now!

 

I only have one question: Will it properly escape characters in strings passed to it? I might need to be saving arbitrary data as strings, and I don't know if I need to escape things manually.

 

Also, a suggestion: Maybe you can also give us functions to turn a JSO list/map into a native GM ds_list/ds_map, so we don't have to use the (confusing to me) "lookup" functions? I guess I just need to learn how lookup works, but...

 

EDIT: wait, it seems you actually use ds_list/ds_map under the hood anyways? NICE. Nevermind them!


Edited by iconmaster, 11 January 2014 - 09:09 PM.

  • 0

#23 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 11 January 2014 - 11:29 PM

I only have one question: Will it properly escape characters in strings passed to it? I might need to be saving arbitrary data as strings, and I don't know if I need to escape things manually.

 

Yes, JSOnion escapes characters for you.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#24 iconmaster

iconmaster

    GMC Member

  • GMC Member
  • 22 posts
  • Version:GM8.1

Posted 12 January 2014 - 03:32 PM

I seem to be experiencing a rather odd bug with JSOnion. If I call enough jso scripts, random other ds_lists in my game will be overwritten with jso's ds_lists. Is this a bug with GM not properly generating new ds_list IDs, or is there something in JSonion?

 

EDIT: Here's an example. It's probably not useful, but it shows my point. I have a routine for displaying a ds_list of choices as a dialog. It's getting passed a random JSO list instead of the one I explicitly send it (it's only a simple "yes" "no" 2-item list!):

Spoiler


Edited by iconmaster, 12 January 2014 - 03:39 PM.

  • 0

#25 thewanderingtree

thewanderingtree

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 26 February 2014 - 04:19 AM

Hi GameGeisha,

 

This is the best thing ever! I honestly Can't imagine using ds_lists and ds_maps without JSOnion. I am running into some difficulties however, and would like your advice.

 

I have a huge list of submaps nested within a JSON object, and I'd like to be able to copy a few of these submaps into a new JSO list, which I have created outside of my decoded JSON structure. Basically I'm pulling a handful of active maps to use in my game, from an array of possible maps. The reason here being that I want to be able to simply cleanup the decoded JSON map, and still keep the submaps that have been added to my new list. From my experience, when I use jso_list_add_submap, it doesn't create a new ID for the map, it references the same ID from the JSON object. So when I cleanup the JSON data, I can still use jso_list_get to return the submap's ID, but when I try to retrieve any values from that map, it says the data structure doesn't exist.

 

My only workaround so far has been to manually create new JSO maps which are empty, and append them to the new JSO list beforehand. Then use ds_map_copy to replace the empty maps with the decoded submaps from the JSON file. This feels inefficient however, because I don't always know how many empty maps I need to create beforehand. Is there a way to add a submap to an empty list, and give it its own ds_map ID?

 

Thanks!


  • 1

#26 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 28 February 2014 - 02:46 AM

Hi GameGeisha,
 
This is the best thing ever! I honestly Can't imagine using ds_lists and ds_maps without JSOnion. I am running into some difficulties however, and would like your advice.
 
I have a huge list of submaps nested within a JSON object, and I'd like to be able to copy a few of these submaps into a new JSO list, which I have created outside of my decoded JSON structure. Basically I'm pulling a handful of active maps to use in my game, from an array of possible maps. The reason here being that I want to be able to simply cleanup the decoded JSON map, and still keep the submaps that have been added to my new list. From my experience, when I use jso_list_add_submap, it doesn't create a new ID for the map, it references the same ID from the JSON object. So when I cleanup the JSON data, I can still use jso_list_get to return the submap's ID, but when I try to retrieve any values from that map, it says the data structure doesn't exist.
 
My only workaround so far has been to manually create new JSO maps which are empty, and append them to the new JSO list beforehand. Then use ds_map_copy to replace the empty maps with the decoded submaps from the JSON file. This feels inefficient however, because I don't always know how many empty maps I need to create beforehand. Is there a way to add a submap to an empty list, and give it its own ds_map ID?
 
Thanks!

 

There is a way, and it would be meaningful for JSOnion have built-in support for it in the future.

 

Add these two scripts to your JSOnion installation:

 

jso_clone_map()

Spoiler

 
jso_clone_list()
Spoiler
 

 

Instead of adding the submaps directly to the new list, add clones of them instead:

jso_list_add_submap(jso_clone_map(submap));

The clones are independent and won't get swept away if the original is cleaned up. The clones are deep copies, so nested structures within the submap are also intact but with new IDs distinct from the original.

 

Thank you for your feedback! These functions will become a standard part of the library in the next minor release.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#27 thewanderingtree

thewanderingtree

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 11 March 2014 - 08:13 PM

Thanks so much, GameGeisha! These scripts work beautifully.


  • 0

#28 Alice

Alice

    Toolmaker of Bucuresti

  • GMC Member
  • 1392 posts
  • Version:GM:Studio

Posted 02 May 2014 - 01:50 PM

Hello there!
I got linked to your set of scripts and I'll probably be using them, at least until YYG staff adds a way to retrieve whether a given entry is marked as a list, map or real/int/bool value, since without that making deep copies of arbitrary JSON trees becomes impossible (the deep deletion is apparently already built-in, huh ^^").

A suggestion, though - could you please add an argument list at the beginning of exposed scripts so that IDE would show these? As in, like that:
///jso_list_get_type(list,index)
(not that I can't add them myself, but I guess future users of your scripts would like to have that included already)

Edited by Alice, 02 May 2014 - 01:51 PM.

  • 0


LShy6C6.png


#29 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 27 August 2014 - 10:07 AM

I try to decode this nested map and it's imposible for me. Don´t know whats going on, the runner just do nothing and i have to kill the process.

 

http://www.tomasabas.es/champion.json


  • 0

#30 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 27 August 2014 - 04:47 PM

I try to decode this nested map and it's imposible for me. Don´t know whats going on, the runner just do nothing and i have to kill the process.

 

http://www.tomasabas.es/champion.json

 

That link is broken, please fix it or provide a copy-and-paste sample.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#31 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 27 August 2014 - 05:19 PM

Sorry wrong link :(

www.tomasabad.es/champion.json
  • 0

#32 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 27 August 2014 - 06:28 PM

JSOnion took around 40 seconds on my machine to process your JSON, but it did finish decoding. Your JSON is 111 kB long and contains extensive nesting. Serving each champion separately should help reduce unresponsiveness.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#33 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 28 August 2014 - 09:25 AM

JSOnion took around 40 seconds on my machine to process your JSON, but it did finish decoding. Your JSON is 111 kB long and contains extensive nesting. Serving each champion separately should help reduce unresponsiveness.

 

GameGeisha

 

 

You are right. If i wait a minute the Runner works :(.

 

Ok, i have the champion files separatly but still have problems. All separate files give me a error.

############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object test_obj:

Unexpected character at position 5878. n
 at gml_Script__jso_decode_list (line 74) -                             show_error("Unexpected character at position " + string(i) + ". " + string(c), true);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script__jso_decode_list (line 74)
called from - gml_Script__jso_decode_map (line 75) -                         found = _jso_decode_list(argument0, i);
called from - gml_Script__jso_decode_list (line 47) -                         found = _jso_decode_map(argument0, i);
called from - gml_Script__jso_decode_map (line 75) -                         found = _jso_decode_list(argument0, i);
called from - gml_Script__jso_decode_map (line 81) -                         found = _jso_decode_map(argument0, i);
called from - gml_Script__jso_decode_map (line 81) -                         found = _jso_decode_map(argument0, i);
called from - gml_Script_jso_decode_map (line 6) -     return __jso_gmt_elem(_jso_decode_map(argument0, 1), 0);
called from - gml_Object_test_obj_CreateEvent_1 (line 20) - json_data = jso_decode_map(json);

Don't know how to fix it.

 

 

EXAMPLE FILE:

www.tomasabad.es/Aatrox.json


  • 0

#34 booksmaster

booksmaster

    GMC Member

  • GMC Member
  • 63 posts
  • Version:GM:Studio

Posted 21 March 2015 - 05:47 PM

Hi! Did you quit working on that project? It would be very nice to have null type working. And also Id like to have one important feature. To have false returned in case of error but not crash game.


  • 0

#35 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 09 February 2016 - 03:32 AM

JSOnion 1.1.0 has been released!
 
This version adds support for the null data type, which should allow more JSON strings from web APIs to parse correctly without crashes. Please add the constants jso_type_null (set to 5) and jso_value_of_null (set to undefined for GMS or "" for GM8.1) to your project if you are migrating from 1.0.0d or below.
 
The next and likely final version of JSOnion 1.x will add support for path-like lookups (e.g. "data/users/0/score") and tolerant parsing (returning a negative error position or partial result instead of throwing an error). JSOnion 2.x will drop support for 8.1 in favour of major performance boosts offered by Studio-exclusive functionality, which will significantly accelerate the parsing of large JSON files.
 
GameGeisha

Edited by GameGeisha, 29 February 2016 - 10:56 PM.

  • 1
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)

#36 xDGameStudios

xDGameStudios

    GMC Member

  • GMC Member
  • 71 posts

Posted 01 March 2016 - 02:13 AM

JSOnion 1.1.0 has been released!
 
This version adds support for the null data type, which should allow more JSON strings from web APIs to parse correctly without crashes. Please add the constants jso_type_null (set to 5) and jso_value_of_null (set to undefined for GMS or "" for GM8.1) to your project if you are migrating from 1.0.0d or below.
 
The next and likely final version of JSOnion 1.x will add support for path-like lookups (e.g. "data/users/0/score") and tolerant parsing (returning a negative error position or partial result instead of throwing an error). JSOnion 2.x will drop support for 8.1 in favour of major performance boosts offered by Studio-exclusive functionality, which will significantly accelerate the parsing of large JSON files.
 
GameGeisha

Great work GameGeisha I really have to give you congrats for your work.
I have some questions I want to ask though, I'm working on a RPG project and this is really a tool I'll need for editor database data like items, weapons, armors.... my problem is... I'm looking for a way to create the JSON externally... as I understand.. that would not work with your technique to store.. data adding the initials to the type of data being stored.
What do you suggest? Any ideas? I could create the data inside gamemaker but wouldn't it be redundant? that way I wouldn't need to save it.. as it would already be there xD no?! of course data that has to be saved will still need to be stored somehow so your extensions still is needed, but for default data... I'll a little stuck right here.. xD
Thank you for you time


  • 0

#37 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 06 March 2016 - 04:43 AM

Great work GameGeisha I really have to give you congrats for your work.

I have some questions I want to ask though, I'm working on a RPG project and this is really a tool I'll need for editor database data like items, weapons, armors.... my problem is... I'm looking for a way to create the JSON externally... as I understand.. that would not work with your technique to store.. data adding the initials to the type of data being stored.
What do you suggest? Any ideas? I could create the data inside gamemaker but wouldn't it be redundant? that way I wouldn't need to save it.. as it would already be there xD no?! of course data that has to be saved will still need to be stored somehow so your extensions still is needed, but for default data... I'll a little stuck right here.. xD
Thank you for you time

 

 

The prefixes are only used internally to distinguish types, they will not appear in nor be required for any actual JSON input or output. The scripts will automatically filter them out for you.

 

GameGeisha


  • 0
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)