Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because <code>undefined</code> is not valid <a href="http://json.org/" rel="nofollow">JSON</a>. JSON doesn't have the JavaScript concept of <code>undefined</code>. It does have <code>null</code>, which is vaguely similar, but the usual thing (for better or worse) is to simply omit properties whose values would be <code>undefined</code>.</p> <p>I'm surprised if Dojo's <code>toJson</code> produces invalid JSON like that. You might consider using <a href="https://github.com/douglascrockford/JSON-js/" rel="nofollow">Crockford's <code>JSON.stringify</code></a> instead. If Dojo's <code>toJson</code> is really doing that, I'd report it as a bug to the Dojo team.</p> <p><strong>Update</strong>: Apparently someone <a href="http://bugs.dojotoolkit.org/ticket/11433" rel="nofollow"><em>did</em> report it to them</a>, and they closed it as invalid on the "garbage in, garbage out" theory. Not my project, but that's just totally <em>not</em> how I would handle properties with <code>undefined</code> values... I'd omit them or throw an exception.</p> <p><strong>Update 2</strong>: As you may know, the <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" rel="nofollow">ECMAScript 5th edition specification</a> defines a <code>JSON</code> object with <code>parse</code> and <code>stringify</code> which browsers are adding support for. The specification's definition of <code>JSON.stringify</code> says <em>"<code>undefined</code> values are not rendered"</em> (Section 15.12.3, Note 2)&nbsp;&mdash; e.g., the property should be omitted. Perhaps if you point that out to the Dojo team, they'll rethink their GIGO response to the bug report. Also note @Felix's comment below: They omit function references, which also can't be validly represented in JSON, but apply a different rule to <code>undefined</code>.</p> <p><strong>Update 3</strong>: Still broken in Dojo 1.6.1. Here's a <a href="http://jsbin.com/eruka4/3" rel="nofollow">live test</a> of v1.6.0, which is the latest on the CDNs. I've also tested v1.6.1 and it's still broken there too. (Not going to post a test page hotlinking to their download section, though, that would be rude.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload