toJSON
Creates a plain JavaScript object which contains all fields of the Model
. Inherited from kendo.data.ObservableObject
. For more information and examples, refer to the toJSON
API reference.
Example
<script>
var Product = kendo.data.Model.define({
id: "productId",
fields: {
productId: { type: "number" },
name: { type: "string" },
price: { type: "number" },
category: { type: "string" }
}
});
var product = new Product({
productId: 1,
name: "Wireless Mouse",
price: 29.99,
category: "Computer Accessories"
});
var jsonObject = product.toJSON();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(jsonObject); // outputs { productId: 1, name: "Wireless Mouse", price: 29.99, category: "Computer Accessories" }
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(typeof jsonObject); // outputs "object" - it's a plain JavaScript object
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(JSON.stringify(jsonObject)); // outputs JSON string representation
</script>
In this article