EN
JavaScript - serialize object to json
12
points
In JavaScript, it is possible to serialize objects to JSON in the following way.
1. JSON.stringify
method example
// ONLINE-RUNNER:browser;
var studentObject = {
name: 'John',
age: 25,
todos: [
'Sleeping',
'Lectures',
'Classes',
'Shopping'
]
}
var studentJson = JSON.stringify(studentObject);
console.log(studentJson);
Note:
JSON.stringify
method has been introduced in ES5.