cxflag203 / superobject

Automatically exported from code.google.com/p/superobject
0 stars 0 forks source link

Error parsing simple JSON : space added to identifier. #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Given the following code

Var
  R : ISuperObject;

begin
  R:=SO('{Readers : []}');
end;

Then

R.A['Readers'] is nil.

Instead,

R.A['Readers '] contains the array. 

Obviously, the space should not be there. 

Removing the space after 'Readers':

  R:=SO('{Readers: []');

gives expected result, that is:

R.A['Readers'] 

contains the array.

In JavaScript, the space is ignored. 
(unless you put quotes around it, of course)

Original issue reported on code.google.com by mich...@freepascal.org on 27 Mar 2012 at 7:18

GoogleCodeExporter commented 9 years ago
Yes, javascript lets you write code like your example, but the SuperObject 
library is not a JavaScript interpreter. 

Your example is not valid JSON. If you look at the specification on 
http://www.json.org/, you'll see a pair is made up like string:value, and that 
strings need to have double (not single!) quotes.

Anyway, I have to say that I've encountered the quote-less variant more often, 
so it's nice to see that SuperObject attempts to parse this anyway. 
It would be nice if SuperObject is able to deal with commonly found errors like 
these.

Original comment by woutervannifterick on 30 Mar 2012 at 7:59