Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#5865 closed enhancement (wontfix)

Allow User To Specify A Reviver Function For Parsing JSON In AJAX Requests

Reported by: MrKWatkins Owned by:
Priority: minor Milestone: 1.4.1
Component: ajax Version: 1.4
Keywords: Cc:
Blocked by: Blocking:

Description

The native JSON.parse method allows an optional reviver function to be specified; this allows you to do things such as convert strings into Date objects. It would be nice if jQuery allowed the user to specify a reviver function to use with the JSON parsing done inside the httpData function. To use a reviver currently you have to process the data as text and handled the JSON parsing yourself.

Change History (2)

comment:1 Changed 10 years ago by dmethvin

It's a little bit tricky. jQuery only can use a native JSON parser if one exists. If there isn't one, it evaluates the code using "new Function" which wouldn't be able to use the reviver. That could cause some bugs because the developer would expect the reviver to be used in all cases. So if you are depending upon a JSON implementation that can take a reviver it's safest to ask for text and parse it yourself.

comment:2 Changed 9 years ago by snover

Resolution: wontfix
Status: newclosed

json2.js manages to allow the use of a reviver, but I think the fact of the matter is that very few people actually care about this, and those that do can duck punch $.parseJSON to add support for it.

Note: See TracTickets for help on using tickets.