Categories

jQuery.fromJSON()

Categories: Utilities

jQuery.fromJSON( json )Returns: string

Plugin: jQuery.json

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

  • jQuery.fromJSON( json )

    version added: 1.3

    json   The JSON string to parse.

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

The $.fromJSON() method is defined according to an API standard of converter methods. For example jQuery.toUTF8 and jQuery.fromUTF8 respectively jQuery.toBASE64 and jQuery.fromBASE64. So $.fromJSON() is just the opposite of jQuery.toJSON and is equal to jQuery.parseJSON.

For browsers which don't support a native JSON methods, the jQuery.json plugin will load the jQuery.json.fix plugin automatically.

  • Get an object from JSON string.

    Code:
    $.fromJSON('{"banana":"yellow","strawberry":"red","group":{"red":"strawberry","blue":["berry","other","[]"]}}');
    Results:
    {
        banana: "yellow",
        strawberry: "red",
        group: {
            red: "strawberry",
            blue: [ "berry", "other", "[]" ]
        }
    }