class method Object.toJSON

View source on GitHub →

Object.toJSON(object) → String
  • object (Object) – The object to be serialized.

Returns a JSON string.

undefined and function types have no JSON representation. boolean and null are coerced to strings.

For other types, Object.toJSON looks for a toJSON method on object. If there is one, it is used; otherwise the object is treated like a generic Object.

For more information on Prototype's JSON encoder, hop to our tutorial.

var data = {name: 'Violet', occupation: 'character', age: 25, pets: ['frog', 'rabbit']};
//-> '{"name": "Violet", "occupation": "character", "age": 25, "pets": ["frog","rabbit"]}'