• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Has anyone tried using the new Structs with json_encode/json_decode?

BoB3k

Member
Has anyone tried using the new Structs with json_encode/json_decode?

My guess is that they go away, as in they will work fine on the encode, but on decode they will just be turned into ds_maps as before.

It's too bad. It would be nice to have a json decode into structs, as that would closer resemble the json and OO structuring.

Maybe there could be an option in the decode function to request structs instead of ds_maps?
 

Alice

Darts addict
Forum Staff
Moderator
According to these release notes, there is json_stringify function fixed for HTML5, and the speaker of squirrels did mention json_parse/json_stringify being struct-based counterparts to json_decode/json_encode.

They are available since 2.3.1 Beta, though, they are not yet available in 2.3.0. Or at least, my 2.3.0 GM:S doesn't show any such function existing (I haven't tried out 2.3.1 beta yet).
 

BoB3k

Member
So, I just went and looked around the yoyo site and this forum and I see nothing about a 2.3.1 beta, betas in general, or any mention of a json_parse()...
 

hippyman

Member
Has anyone tried using the new Structs with json_encode/json_decode?

My guess is that they go away, as in they will work fine on the encode, but on decode they will just be turned into ds_maps as before.

It's too bad. It would be nice to have a json decode into structs, as that would closer resemble the json and OO structuring.

Maybe there could be an option in the decode function to request structs instead of ds_maps?
If I'm understanding correctly I put together exactly that a few weeks ago.
Check out the functions posted here.
 

BoB3k

Member
The beta is in "GameMaker Studio 2 Community Tech Support" rather than in "Announcements" forum, though, so I can understand why it was not trivial to find.
Ah, I didn't even notice the 'speaker of squirrels' was a link, and just looked at the release notes. I've got it now.

As a side note, it still took me awhile to find the actual beta download, as the download link on the release notes page is not lit up like a link at all and just looks like a header for the page.
 

BoB3k

Member
I did try and json_encode a map with structs in it. It doesn't work. it puts a key in, but then puts an empty {} in even though I have data in it.
 

BoB3k

Member
If I'm understanding correctly I put together exactly that a few weeks ago.
Check out the functions posted here.
Yes, I went ahead and made my own that are very similar to yours. It does look like one is needed going the other way too since json_encode doesn't handle structs back out even though it handles arrays okay.
 
Top