Skip to main content

Bug Tracker

Side navigation

#5774 closed bug (invalid)

Opened January 08, 2010 11:18AM UTC

Closed January 08, 2010 02:31PM UTC

Last modified January 11, 2010 03:11AM UTC

$.getJSON does not work as before

Reported by: Jessige Owned by:
Priority: major Milestone: 1.4
Component: ajax Version: 1.4a2
Keywords: JSON Cc:
Blocked by: Blocking:

The server returns data likes {text: "test"} in my application, $.getJSON works well in 1.3.2, but not in 1.4a2, an error occured instead.

The reason is -

The line 4868~4875 of jquery-1.4a2.js:

// Get the JavaScript object, if JSON is used.
if ( type === "json" ) {
    if ( typeof JSON === "object" && JSON.parse ) {
        data = JSON.parse( data );
    } else {
        data = (new Function("return " + data))();

I think {text: "test"} is not illegal, whatever, the two ways have different behaviors: if I make JSON = null, or I use Firefox2 or some other browsers, my application works well.

Attachments (0)
Change History (2)

Changed January 08, 2010 02:31PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed
I think {text: "test"} is not illegal

Yes it is, read the spec:

I think you meant

 {"text": "test"} 

Some implementations may parse it, but it is still invalid.

Feel free to first read and then comment here, there is some discussion about whether to allow broken JSON to be parsed.

Changed January 11, 2010 03:11AM UTC by Jessige comment:2

Replying to [comment:1 dmethvin]:

Yeah, some implementations parse it - almost all the browsers, that is why the two ways have different behaviors in them.

I think the loose rule is better although it is invalid. And maybe it is VALID in Javascript, Javascripters always code like this:

var something = {

element1: "something",

element2: "something"


So does JQuery, except the element name like this "ele-ment" or "null", that is Javascripters' habit. If they can not do that in JSON(maybe only in Firefox), they will be surprised, whatever, I will be surprised.

So, could you think over it?