back to Overview

$.toJSON()

Converts the given value into a JSON string.
Web module only.

Syntax

$.toJSON(value)

Parameters

value
the value (map-like object, array/list, string, number, boolean or null)
(return value)
the JSON string

Description

Converts the given value into a JSON string. The value may be a map-like object, an array or list, a string, number, boolean or null. If you build Minified without Internet Explorer compatibility, this is just an alias for JSON.stringify.

The following types are supported by the built-in implementation:

  • Objects (direct properties will be serialized)
  • Arrays/Lists (with length property)
  • Strings
  • Numbers
  • Boolean
  • null
Any other types in your JSON tree, especially Dates, should be converted into Strings before being passed to toJSON.

Example

Converts an object into a JSON object:

var myObj = {name: 'Fruits', roles: ['apple', 'banana', 'orange']};
var jsonString = $.toJSON(myObj);

See also..

Comments

comments powered by Disqus

back to Overview

Functions