Skip to content

$.parseJSON: Clarify valid inputs #243

@dmethvin

Description

@dmethvin

It was our goal to have $.parseJSON behave identically to the JSON.parse() method. The docs are ambiguous about this.

Takes a well-formed JSON string and returns the resulting JavaScript object.

This is correct.

Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string.

This is correct.

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

An empty string or undefined are not valid well-formed JSON strings and shouldn't return a null, but instead JSON.parse() throws an error. The documented behavior is the actual behavior of $.parseJSON() prior to 1.9.0 but we didn't intend to document a divergence from spec here or turn invalid JSON into a valid case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions