json serialize javascript code example
Example 1: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 2: node json stringify
let data = {
name: "John Smith",
age: 30,
hobbies: ["Programming", "Video Games"]
};
let miny = JSON.stringify(data);
let pretty = JSON.stringify(data, null, 4);
Example 3: json.stringify file object return {}
var fileObject = getFile();
var newObject = {
'lastModified' : fileObject.lastModified,
'lastModifiedDate' : fileObject.lastModifiedDate,
'name' : fileObject.name,
'size' : fileObject.size,
'type' : fileObject.type
};
JSON.stringify(newObject);