Ticket #4429 (closed enhancement: fixed)
Use native JSON.parse if available inside ajax.httpData
| Reported by: | hakanson | Owned by: | flesler |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.4 |
| Component: | ajax | Version: | 1.3.2 |
| Keywords: | JSON | Cc: | hakanson, flesler |
| Blocking: | Blocked by: |
Description
In jQuery.ajax.httpData, would you consider using the native JSON support ( http://www.json.org/js.html) if available? Below is some untested sample code. Maybe the (JSON && JSON.parse) check is better located under jQuery.support.JSON and could be expanded to check if JSON.parse is a function?
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
if (JSON && JSON.parse)
data = JSON.parse(data);
else
data = window["eval"]("(" + data + ")");
Change History
comment:1 Changed 4 years ago by flesler
- Cc hakanson, flesler added
- Status changed from new to closed
- Resolution set to invalid
comment:2 Changed 4 years ago by hakanson
- Status changed from closed to reopened
- Resolution invalid deleted
Native JSON parse and stringify will be a built-in browser feature in Firefox 3.1 and IE8. That json.org link just referenced a compatible library. Sorry for the confusion, but I think it is a legitimate request and has a performance advantage.
http://ajaxian.com/archives/native-json-in-firefox-31-joins-ie-8
comment:3 Changed 4 years ago by flesler
- Owner set to flesler
- Status changed from reopened to new
Then we probably will add compatibility with it once it's established.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

We don't rely on this kind of things, only built-in browser features like querySelectorAll.
You can always add it for yourself using $.ajax's 'dataFilter' setting added since 1.3.
More here: http://dev.jquery.com/ticket/3231