View Issue Details

IDProjectCategoryView StatusLast Update
0026867RunnerFunctionsPublic2019-01-30 15:47
ReporterEric BuneseAssigned ToAlan Savage 
PriorityMediumSeverityC - GeneralReproducibility100%
Status ClosedResolutionFixed 
PlatformWindowsOSOS Version
Product VersionPre-2.1.3 
Target Version2.2.2Fixed in Version2.2.2 
Summary0026867: Functions: [GMS2] json_decode () doesn't strip BOM properly in http_get() results, breaks data parsing
DescriptionThe ability to deal with json was a great addition to game maker. But when I attempted to include this possibility in my new GMS2.0 game, I noticed there are serious problems;

-You have to escape double quotes, even when the string comes from a webserver/http request.
-Lists of objects are problematic.

I've created a thorough sample project which I am anexing to this report, which will be able to demonstrate the problems reported above.

Please read the object 'jsontest', the script 'escape_json' and test running the game on windows with both configurations; 'default' and 'FORCE_ERROR'.

The FORCE_ERROR configuration makes the script escape_json not escape the double quotes, causing a parse error in the json_decode function when the json has a list of objects. Because of this, json_decode returns -1. If the json is a simple array of strings, the behaviour is perfect, even when the configuration is set to FORCE_ERROR.
Steps To ReproduceUse variables to hold json and parse them, or load json from a server using an HTTP REQUEST, detect several problems when decoding and parsing the data structure
Tagsfunctions, HTTP, JSON, Runner
1.4 Found In2.0.6.146
2.x Runtime Found In2.0.6.96
2.x Runtime Verified In2.2.2.302


Eric Bunese

2017-06-17 22:36


jsontest.yyz (16,712 bytes)

Eric Bunese

2017-07-05 23:44

Updater   ~0054053

I have found a workaround;
if you save async_load[?"result"] in a text file, and read the string from it again, the decoding will work just fine. Apparently, the problem comes from http get/posts

Eric Bunese

2017-11-13 13:16

Updater   ~0056560

Any updates on this matter?
I've been using the workaround for a while now and it's not practical

Alan Savage

2018-11-21 14:40

Developer   ~0062109

Note that the json text examples in this project decode correctly without any escaping required - issue was only occurring for the json returned from the http_get, due to a byte order mark at the beginning of the returned string.
Fixed by stripping byte order mark if present in json_decode. (saving to a file and reloading also strips the BOM hence workaround mentioned below)