Dojo usage of non-standard JSON Format

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Dojo usage of non-standard JSON Format

lazaridis_com
After struggling around for some hours, I've found out that the tree-demos (and _lots_ of documentation) do _not_ use JSON as a format, although they mention it as JSON. Additionally, the file-extensions (*.json) imply this.

Example:

{ id: 'CN', name:'China', type:'country' }

The above  format is _not_ JSON, according to:

http://www.json.org/

The following should be JSON (double quotes for names, double quotes for string values):

{ "id": "CN", "name": "China", "type": "country" }

Why is this so, and why isn't it mentioned within the documentation?

Is there any configuration option to switch dojo to use the standard?
Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

Eric Pasquier
Hi,
It is not related to Dojo directly; but to the interpretation of Javascript
in the browser.
Modern browsers are quite tolerant about the json format and work of course
if you use the documented syntax, which I recommand if you want to use the
validator and be the most compatible as possible.

Eric.

----- Original Message -----
From: "lazaridis_com" <[hidden email]>
To: <[hidden email]>
Sent: Friday, April 29, 2011 9:17 AM
Subject: [Dojo-interest] Dojo usage of non-standard JSON Format


> After struggling around for some hours, I've found out that the tree-demos
> (and _lots_ of documentation) do _not_ use JSON as a format, although they
> mention it as JSON. Additionally, the file-extensions (*.json) imply this.
>
> Example:
>
> { id: 'CN', name:'China', type:'country' }
>
> The above  format is _not_ JSON, according to:
>
> http://www.json.org/
>
> The following should be JSON (double quotes for names, double quotes for
> string values):
>
> { "id": "CN", "name": "China", "type": "country" }
>
> Why is this so, and why isn't it mentioned within the documentation?
>
> Is there any configuration option to switch dojo to use the standard?--
> View this message in context:
> http://dojo-toolkit.33424.n3.nabble.com/Dojo-usage-of-non-standard-JSON-Format-tp2878366p2878366.html
> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

Kenneth G. Franqueiro
I'd have to beg to differ from Eric's reply: browsers are not loose
about JSON syntax, if they implement JSON.parse.  *Eval* is "loose"
about JSON syntax, since when you eval, you're parsing JavaScript, not
JSON (which is effectively a small subset of the JS syntax).

 From what I understand, back when Dojo 1.0 (or maybe 0.9?) was written,
JSON parsers weren't nearly as common as they are now (what with it
being a standard part of ES5 and thus modern browsers).  The original
implementation of dojo.fromJson doesn't use JSON.parse, it simply evals.
  Due to the high priority of backwards-compatibility within 1.x, this
has to continue working this way by default, otherwise it would
potentially break many users' code which (as lazaridis says) isn't
actually using valid JSON.  This default behavior therefore isn't likely
to change any time before 2.0.

In Dojo 1.6, there is a dojox.secure.fromJson module which will give you
a fromJson method which actually parses rather than simply evals (it'll
simply use JSON.parse if the browser supports it).  You can perhaps hook
that up in place of dojo.fromJson if you're interested in going that route.

--Ken

On 4/29/2011 4:02 AM, Eric Pasquier wrote:

> Hi,
> It is not related to Dojo directly; but to the interpretation of Javascript
> in the browser.
> Modern browsers are quite tolerant about the json format and work of course
> if you use the documented syntax, which I recommand if you want to use the
> validator and be the most compatible as possible.
>
> Eric.
>
> ----- Original Message -----
> From: "lazaridis_com"<[hidden email]>
> To:<[hidden email]>
> Sent: Friday, April 29, 2011 9:17 AM
> Subject: [Dojo-interest] Dojo usage of non-standard JSON Format
>
>
>> After struggling around for some hours, I've found out that the tree-demos
>> (and _lots_ of documentation) do _not_ use JSON as a format, although they
>> mention it as JSON. Additionally, the file-extensions (*.json) imply this.
>>
>> Example:
>>
>> { id: 'CN', name:'China', type:'country' }
>>
>> The above  format is _not_ JSON, according to:
>>
>> http://www.json.org/
>>
>> The following should be JSON (double quotes for names, double quotes for
>> string values):
>>
>> { "id": "CN", "name": "China", "type": "country" }
>>
>> Why is this so, and why isn't it mentioned within the documentation?
>>
>> Is there any configuration option to switch dojo to use the standard?--
>> View this message in context:
>> http://dojo-toolkit.33424.n3.nabble.com/Dojo-usage-of-non-standard-JSON-Format-tp2878366p2878366.html
>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

Eric Pasquier
Hi Ken,
Feel free to comment my poor knowledge of dojo ;-)

The question was : "Is there any configuration option to switch dojo to use
the standard ?".
From my point of view, you have nothing to do.
The use of json.parse or, most of the time, eval, to interprete json data in
dojo is related to the implementation of the browser.

But it is true that lots of example use a wrong syntax, which may be
improved to avoid confusion.
Eric.


----- Original Message -----
From: "Kenneth G. Franqueiro" <[hidden email]>
To: <[hidden email]>
Sent: Friday, April 29, 2011 2:08 PM
Subject: Re: [Dojo-interest] Dojo usage of non-standard JSON Format


> I'd have to beg to differ from Eric's reply: browsers are not loose
> about JSON syntax, if they implement JSON.parse.  *Eval* is "loose"
> about JSON syntax, since when you eval, you're parsing JavaScript, not
> JSON (which is effectively a small subset of the JS syntax).
>
> From what I understand, back when Dojo 1.0 (or maybe 0.9?) was written,
> JSON parsers weren't nearly as common as they are now (what with it
> being a standard part of ES5 and thus modern browsers).  The original
> implementation of dojo.fromJson doesn't use JSON.parse, it simply evals.
>  Due to the high priority of backwards-compatibility within 1.x, this
> has to continue working this way by default, otherwise it would
> potentially break many users' code which (as lazaridis says) isn't
> actually using valid JSON.  This default behavior therefore isn't likely
> to change any time before 2.0.
>
> In Dojo 1.6, there is a dojox.secure.fromJson module which will give you
> a fromJson method which actually parses rather than simply evals (it'll
> simply use JSON.parse if the browser supports it).  You can perhaps hook
> that up in place of dojo.fromJson if you're interested in going that
> route.
>
> --Ken
>
> On 4/29/2011 4:02 AM, Eric Pasquier wrote:
>> Hi,
>> It is not related to Dojo directly; but to the interpretation of
>> Javascript
>> in the browser.
>> Modern browsers are quite tolerant about the json format and work of
>> course
>> if you use the documented syntax, which I recommand if you want to use
>> the
>> validator and be the most compatible as possible.
>>
>> Eric.
>>
>> ----- Original Message -----
>> From: "lazaridis_com"<[hidden email]>
>> To:<[hidden email]>
>> Sent: Friday, April 29, 2011 9:17 AM
>> Subject: [Dojo-interest] Dojo usage of non-standard JSON Format
>>
>>
>>> After struggling around for some hours, I've found out that the
>>> tree-demos
>>> (and _lots_ of documentation) do _not_ use JSON as a format, although
>>> they
>>> mention it as JSON. Additionally, the file-extensions (*.json) imply
>>> this.
>>>
>>> Example:
>>>
>>> { id: 'CN', name:'China', type:'country' }
>>>
>>> The above  format is _not_ JSON, according to:
>>>
>>> http://www.json.org/
>>>
>>> The following should be JSON (double quotes for names, double quotes for
>>> string values):
>>>
>>> { "id": "CN", "name": "China", "type": "country" }
>>>
>>> Why is this so, and why isn't it mentioned within the documentation?
>>>
>>> Is there any configuration option to switch dojo to use the standard?--
>>> View this message in context:
>>> http://dojo-toolkit.33424.n3.nabble.com/Dojo-usage-of-non-standard-JSON-Format-tp2878366p2878366.html
>>> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> [hidden email]
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> [hidden email]
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

lazaridis_com
In reply to this post by Kenneth G. Franqueiro
>> After struggling around for some hours, I've found out that the tree-demos
>> (and _lots_ of documentation) do _not_ use JSON as a format, although they
>> mention it as JSON. Additionally, the file-extensions (*.json) imply this.
[...]
>> Why is this so, and why isn't it mentioned within the documentation?
>>
>> Is there any configuration option to switch dojo to use the standard?--

2011/4/29 Kenneth G. Franqueiro[via Dojo Toolkit] <[hidden email]>
I'd have to beg to differ from Eric's reply: browsers are not loose    
[...] - subjecting browsers JSON processing.

This is not relevant, as the problem is dojo specific.
 
 From what I understand, back when Dojo 1.0 (or maybe 0.9?) was written,
JSON parsers weren't nearly as common as they are now (what with it
being a standard part of ES5 and thus modern browsers).  The original
implementation of dojo.fromJson doesn't use JSON.parse, it simply evals.

"Although this has never been allowed by JSON specification, basic Javascript allows it, and thus there are systems that assume this is legal "
http://wiki.fasterxml.com/JacksonFeaturesNonStandard

Seems to be a common problem.
 
  Due to the high priority of backwards-compatibility within 1.x, this
has to continue working this way by default, otherwise it would
potentially break many users' code which (as lazaridis says) isn't
actually using valid JSON.  This default behavior therefore isn't likely
to change any time before 2.0.

I see, so it's about legacy support.
 

In Dojo 1.6, there is a dojox.secure.fromJson module which will give you
a fromJson method which actually parses rather than simply evals (it'll
simply use JSON.parse if the browser supports it).  You can perhaps hook
that up in place of dojo.fromJson if you're interested in going that route.

This is a too fundamental issue, which I cannot touch at this point.

I was just looking for something like "strictJson:= true|false", on a per store basis, thus being able to deal with legacy pseudo-json-data, and json-data.

 


Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

lazaridis_com
lazaridis_com wrote
[...]
2011/4/29 Kenneth G. Franqueiro[via Dojo Toolkit] <
[...]
> In Dojo 1.6, there is a dojox.secure.fromJson module which will give you
> a fromJson method which actually parses rather than simply evals (it'll
> simply use JSON.parse if the browser supports it).  You can perhaps hook
> that up in place of dojo.fromJson if you're interested in going that route.

This is a too fundamental issue, which I cannot touch at this point.

I was just looking for something like "strictJson:= true|false", on a per
store basis, thus being able to deal with legacy pseudo-json-data, and
json-data.
Related Issue:

http://bugs.dojotoolkit.org/ticket/12871

Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

lazaridis_com
In reply to this post by Eric Pasquier
Eric Pasquier wrote
[...]
But it is true that lots of example use a wrong syntax, which may be
improved to avoid confusion.
Eric.
I've filed a related ticket:

http://bugs.dojotoolkit.org/ticket/12872

If this is JSON (Java Script Object Notation)

{ "id": "CN", "name": "China", "type": "country" }

then what is this?

{ id: 'CN', name:'China', type:'country' }

I suggested *.jsd (java script data). Is there any standard naming for files which contain such data?

Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

Kenneth G. Franqueiro
"It's Just F***ing JavaScript" (to quote Peter Higgins).  No need to
confuse the issue with yet another name/extension.

--Ken

On 5/6/2011 10:57 PM, lazaridis_com wrote:

>
> Eric Pasquier wrote:
>>
>> [...]
>> But it is true that lots of example use a wrong syntax, which may be
>> improved to avoid confusion.
>> Eric.
>>
>
> I've filed a related ticket:
>
> http://bugs.dojotoolkit.org/ticket/12872
>
> If this is JSON (Java Script Object Notation)
>
> { "id": "CN", "name": "China", "type": "country" }
>
> then what is this?
>
> { id: 'CN', name:'China', type:'country' }
>
> I suggested *.jsd (java script data). Is there any standard naming for files
> which contain such data?
>
>
>
> --
> View this message in context: http://dojo-toolkit.33424.n3.nabble.com/Dojo-usage-of-non-standard-JSON-Format-tp2878366p2910734.html
> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Dojo usage of non-standard JSON Format

lazaridis_com
2011/5/7 Kenneth G. Franqueiro [via Dojo Toolkit] <[hidden email]>
On 5/6/2011 10:57 PM, lazaridis_com wrote:
 
[...]
> then what is this?
>
> { id: 'CN', name:'China', type:'country' }
>
> I suggested *.jsd (java script data). Is there any standard naming for files
> which contain such data?

"It's Just F***ing JavaScript" (to quote Peter Higgins).  No need to
confuse the issue with yet another name/extension. 
--Ken

Ok, I understand it's plain js, which JS "eats" via eval().

Still it's data and different from json, thus maybe by convention one could use this form:

countries.data.js or countries.db.js

This would avoid one more extension, would work within editors, would allow human and machine detection of data files.

(See, I personally like the "*.db.js" form, but if there's any convention within the JS domain, I'd like to know. A quick search didn't bring up much)