• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Please add apostrophe / single quote ( ' ) back for strings!

Z

Zatara

Guest
I'm not sure if this is the best place to direct this, but for Mike and other YoYo reps on the boards:
please consider adding back in the apostrophe / single quote for strings!

Removal of this option has broken quite a bit of code/workflows from GMS1, including severely handicapping and complicating JSON support.

Is there any particular reason this functionality was removed? One of GML's strengths is that it's easier to handle than other languages, and necessitating complicated 'escapes' seems like a step backward. I'd implore you to add it back in (or if there's an efficient work around, please let us know!)!

Thank you!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
This is isn't going to happen. It was removed to bring the string handling into line with more common practices...
 
Z

Zatara

Guest
This is isn't going to happen. It was removed to bring the string handling into line with more common practices...
Is there any plan at all to fix the issues with JSON then? The elimination of the apostrophe kills functionality with no obvious additive improvement, and isn't a matter of 'preference'.

I understand it may not be 'common practice' but was the use of the single quote hurting anything? Why kneecap functionality just because others are doing it too?

I don't mean to be negative, but it's extremely frustrating that my workflow from GMS1 now seems trashed, without any gain.
 

gnysek

Member
@Zatara What are JSON issues ? From what I know, using ' in JSON is invalid:

Visit http://jsonlint.com/ and try those:

valid:
Code:
{"a": "b"}
invalid:
Code:
{'a': 'b'}

Error: Parse error on line 1:
{    'a': 'b'}
--^
Expecting 'STRING', '}', got 'undefined'
 
Z

Zatara

Guest
Excatly my point, gnysek. JSON won't allow single quotes, so you need them in GMS to surround the JSON.

Without allowing single quotes, you can't properly process the JSON data. The way YoYo implemented JSON decode, in other words, seems to require single quotes/apostrophes.

So, this code works fine in GMS1 buit does not work in GMS2.
Code:
return json_decode('
{
    "elizabeth" : {
        "name" : "Elizabeth",
        "health" : 10,
        "attack" : 8,
        "defense" : 8,
        "speed" : 9,
        "critical" : 25,
        "experience" : 0,
        "actions" : []
    },
 
    "spider" : {
        "name"          : "Spider",
        "health"        : 3,
        "attack"        : 5,
        "defense"       : 4,
        "speed"         : 10,
        "critical"      : 5,
        "experience"    : 10,
        "actions"       : ["attack", "defend"]
    }
}');
Sticking double quotes around the JSON breaks the function. And using escapes around the internal JSON quotes spits errors in the code editor, and odd behavior in debug.
 
I

icuurd12b42

Guest
Unfortunately yoyo refuses to consider this scenario which everyone who does json uses, as reason enough to implement the single quote system...

use the very awkward \"...
\"actions\" : [\"attack\", \"defend\"]
which makes your beautiful json structure look like crap...

Alternatively, I suggest you put single quotes in your keyname and data
'actions' : ['attack', 'defend']

and do a string_replace_all ' with " before the json decode call... since we are all used to the interchangeability of the " and ', the json will be readable
 

gnysek

Member
and do a string_replace_all ' with " before the json decode call... since we are all used to the interchangeability of the " and ', the json will be readable
Code:
var json = "{'message':'You can't do this'}";
it's not a bad idea, but until you need to use ' in text...

It should be possible to make this:

Code:
var json = @{"message" : "You can't do this"};
.

A @ as a mark that { is not for block of code.
 
Z

Zatara

Guest
It should be possible to make this:

Code:
var json = @{"message" : "You can't do this"};
.

A @ as a mark that { is not for block of code.
Nope, that doesn't work - doesn't compile in GMS2.

Bizarrely, this sort of works:
Code:
global.entities = json_decode("
{
   'player' : {
        'name' : 'Player',
        'health' : 25,
        'attack' : 12,
        'defense' : 5,
        'speed' : 12,
        'experience' : 0,
        'actions' : ['attack', 'defend', 'item', 'run']
    },
   
    'goblin' : {
        'name'          : 'Goblin',
        'health'        : 12,
        'attack'        : 6,
        'defense'       : 2,
        'speed'         : 8,
        'experience'    : 20,
        'actions'       : ['attack', 'defend']
    }
}
");
However, it shows errors in the code view, and doesn't debug properly (the debugger isn't properly attaching variable names, and seems to create an extra data structure, I can't quite tell) - and also won't validate on jsonlint. I certainly wouldn't trust that in a released game.

My sense is that super easy JSON support in GMS1 was something of a happy accident, enabled by YoYo allowing for apostrophes. By eliminating that, they seem to have inadvertently killed JSON support. Again, I sort of get wanting to 'conform' GML to other languages, but why remove significant functionality for no gain? If we're now going to need to adhere to the language restrictions of something like C#, this kills a major reason to use GMS2 over Unity.

Again, if there's a compelling reason this was killed and there's an available, just as effective/easy alternative, please let us know, so we can adjust our practices accordingly.
 
I

icuurd12b42

Guest
Code:
var json = @"
{
'message':'You can<QT>t do this'}
'player' : {
'name' : 'Player',
'health' : 25,
'attack' : 12,
'defense' : 5,
'speed' : 12,
'experience' : 0,
'actions' : ['attack', 'defend', 'item', 'run'] 
},
'goblin' : {
'name' : 'Goblin',
'health' : 12,
'attack' : 6,
'defense' : 2,
'speed' : 8,
'experience' : 20,
'actions' : ['attack', 'defend']
}
}
");
json = string_replace_all(json,"'","\"");
json = string_replace_all(json,"<QT>'","'");
global.entities = json_decode(json);
 
Z

Zatara

Guest
That was a proposal, how it should be solved by YYG, not working solution, sorry for misleading.
Whoops, sorry gnysek, misinterpreted! Based on the other thread though, looks like you were spot on, and that'll be the solution for JSON going forward!
 
Top