Skip to main content

Bug Tracker

Side navigation

#6651 closed feature (wontfix)

Opened June 09, 2010 04:54PM UTC

Closed October 22, 2010 10:30PM UTC

Add a function to pass an object, parsing JSON if needed

Reported by: Chainfire Owned by:
Priority: low Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

Proposal function:

$.obj = function(obj) {

return (typeof obj === "string") ? $.parseJSON(obj) : obj;

}

Can be useful when using a lot of server-generated variables and such, outputted through for example PHP's json_encode. Implementing a function as follows:

$.test = function(obj) {

obj = $.obj(obj);

alert(obj.foo);

alert(obj.bar);

}

One simple extra call allows functions to take both obj's or JSON data directly. Especially useful if you are mixing normal and server-generated content. Using $.obj in a call directly:

$.test($.obj(...))

Now you don't need to keep track of what is JSON and what isn't.

This is of course an easy enough function for everybody to define themselves, but I think a standard API function for this would be beneficial.

Attachments (0)
Change History (2)

Changed June 12, 2010 01:24AM UTC by dmethvin comment:1

component: unfiledajax

Changed October 22, 2010 10:30PM UTC by rwaldron comment:2

priority: → low
resolution: → wontfix
status: newclosed

Your proposed function $.obj appears to wrap $.parseJSON - which is just a sanitizer and fallback wrapper to JSON.parse()