Categories

jQuery.toJSON()

Categories: Utilities

jQuery.toJSON( obj )Returns: string

Plugin: jQuery.json

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

  • jQuery.toJSON( obj )

    version added: 1.0

    obj   A object to stringify.

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

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

  • Stringify an object.

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

jQuery.toJSON( obj )Returns: string

Plugin: jQuery.json.fix

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

  • jQuery.toJSON( obj )

    version added: 1.2

    obj   A object to stringify.

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

The jQuery.json.fix plugin is specially built, for browsers which don't support native JSON methods.