Skip to main content

Bug Tracker

Side navigation

#13430 closed bug (duplicate)

Opened February 11, 2013 04:27AM UTC

Closed September 24, 2013 01:19PM UTC

Error in parseJSON:

Reported by: odesuk@yahoo.com Owned by: odesuk@yahoo.com
Priority: undecided Milestone: None
Component: ajax Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

I had to update code to fix this issue for me.

LIne 548 in jquery-1.9.1.js

Error in IE 10: Invalid character

Added check for null & undefined before calling window.JSON

if (data === null || data === undefined) {

return data;

}

// Attempt to parse using the native JSON parser first

if ( window.JSON && window.JSON.parse ) {

return window.JSON.parse( data );

}

...

Attachments (0)
Change History (11)

Changed February 11, 2013 04:31AM UTC by rwaldron comment:1

#13431 is a duplicate of this ticket.

Changed February 11, 2013 04:31AM UTC by rwaldron comment:2

owner: → odesuk@yahoo.com
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.

To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.

Also, please read: http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/

Changed February 14, 2013 09:36AM UTC by katafrakt comment:3

It's really as simple as typing

$.parseJSON("");

or

$.parseJSON(undefined);

in web console (of Chrome 24.0.1312.57 m or Firefox 21.0a1, both on Windows in my case).

Edge and 1.9.0 are affected.

Changed February 14, 2013 01:36PM UTC by dmethvin comment:4

resolution: → notabug
status: pendingclosed

Ok then, there is your problem. An empty string or undefined are not valid JSON. The jQuery Migrate plugin catches these things for you, and will even fix them if you don't want to change code right now:

https://github.com/jquery/jquery-migrate/blob/master/warnings.md#jqmigrate-jqueryparsejson-requires-a-valid-json-string

Changed February 14, 2013 02:02PM UTC by katafrakt comment:5

Ok, but API docs still state:

"Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON."

Which is kind of misleading.

Changed February 14, 2013 02:09PM UTC by dmethvin comment:6

Agreed. There's a docs ticket open to fix that. Note that it does say the method takes a string, and that it takes a JSON string. Unfortunately someone documented the incorrect behavior at some point.

Changed March 19, 2013 11:50PM UTC by rwaldron comment:7

#13630 is a duplicate of this ticket.

Changed April 10, 2013 05:07AM UTC by Alexpts <alexpts@yandex.ru> comment:8

Is not bug jQuery.

if ( window.JSON && window.JSON.parse ) {
	JSON.parse_original = JSON.parse;
	JSON.parse = function(data){
		return (data == "") ? {} : JSON.parse_original(data);
	}
}

Changed September 13, 2013 01:37PM UTC by dmethvin comment:9

#14360 is a duplicate of this ticket.

Changed September 24, 2013 01:18PM UTC by gibson042 comment:10

resolution: notabug
status: closedreopened

Changed September 24, 2013 01:19PM UTC by gibson042 comment:11

component: unfiledajax
resolution: → duplicate
status: reopenedclosed

Duplicate of #13169.