Opened 11 years ago
Closed 9 years ago
#11433 closed defect (fixed)
dojo.toJson returns invalid JSON for undefined element
Reported by: | mlutton | Owned by: | mlutton |
---|---|---|---|
Priority: | high | Milestone: | 1.7 |
Component: | Core | Version: | 1.4.3 |
Keywords: | toJson | Cc: | |
Blocked By: | Blocking: |
Description
Browser: FireFox? 3.6.6 OS: Microsoft Windows XP SP3 email: [email protected]…
Steps to reproduce:
Define an object with an undefined element, for instance:
var a = {'a':1, 'b':null, 'c':undefined};
Call dojo.toJson(a). Result is:
{"a":1,"b":null,"c":undefined}
The "undefined" is invalid JSON. See JSON syntax at http://www.json.org. When used for an Ajax request for a Web service that expects JSON using the Jackson serializer, the request is rejected.
Change History (6)
comment:1 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Is the undefined value garbage?
Look at the discussion here: http://stackoverflow.com/questions/6185114/why-do-php-function-json-decode-fail-if-string-contains-the-word-undefined-as-a-v
Two arguments:
- It seems unreasonable that we have to 'sanitize for json' first, every time we want to use dojo.toJson. Admittedly it would be great if the undefined value was never returned from any 3rd party library, but we cannot expect that.
- Function references are not transcribed into JSON. Does that make them garbage, and why does dojo.toJson happily omit them?
A reasonable solution would be simply to omit properties with undefined values.
comment:3 Changed 9 years ago by
Owner: | changed from anonymous to mlutton |
---|---|
Status: | reopened → pending |
using dojo.toJson from dojo 1.7 in chrome omits properties with undefined values.
do we need to do anything more with this ticket?
if there's no response it will automatically close in 14 days.
comment:4 Changed 9 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
comment:5 Changed 9 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Should be marked as fixed in 1.7, not invalid.
comment:6 Changed 9 years ago by
Component: | General → Core |
---|---|
Milestone: | tbd → 1.7 |
Resolution: | → fixed |
Status: | reopened → closed |
What is the valid JSON value for undefined in your opinion? It appears that
dojo.toJson()
works correctly: garbage in, garbage out.