EN
JavaScript - serialize object to json
12 points
In JavaScript, it is possible to serialize objects to JSON in the following way.
xxxxxxxxxx
1
var studentObject = {
2
name: 'John',
3
age: 25,
4
todos: [
5
'Sleeping',
6
'Lectures',
7
'Classes',
8
'Shopping'
9
]
10
}
11
12
var studentJson = JSON.stringify(studentObject);
13
14
console.log(studentJson);
Note:
JSON.stringify
method has been introduced in ES5.