Skip to main content

Bug Tracker

Side navigation

#12666 closed bug (notabug)

Opened October 07, 2012 02:01AM UTC

Closed October 07, 2012 03:35AM UTC

$.parseJSON fails for valid json string if it has newlines

Reported by: Owned by:
Priority: undecided Milestone: None
Component: core Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

I think I've found a problem in jQuery's parseJSON function.

Suppose I have the following JSON:

        "hello": "hi\\nlittle boy?"

If you check it using JSONlint you can see it's valid JSON. However, if you try the following, you get an error message:

        $.parseJSON('{ "hello": "hi\\nlittle boy?" }');
    } catch (exception) {

The Official JSON Website says that the "\\n" character is a valid character inside a JSON string.

Attachments (0)
Change History (2)

Changed October 07, 2012 02:02AM UTC by comment:1

I've uploaded a test to jsFiddle.

Changed October 07, 2012 03:35AM UTC by gibson042 comment:2

component: unfiledcore
resolution: → notabug
status: newclosed specifies that strings cannot contain unescaped control characters like newline. If you're specifying data like that, you must escape the backslash so the JSON parser sees it instead of the newline: .