Serializing objects into the JSON format in JavaScript

Prabhukiran345
Posted by Prabhukiran345 under JavaScript category on | Points: 40 | Views : 447
The JSON.stringify() method does the convertion of a JavaScript object into a JSON-formatted string.

JSON.stringify() is a function filters and transform the way a value is stringified

EXAMPLE:
var scores = { "Dhoni": 70, "Dhavan": 80, "Ashwin": 30 };  

var passed = JSON.stringify(scores, function (key, value) {
if (value < 40) {
return undefined;
} else {
return value;
}
});

alert(passed); // {"Dhoni":70,"Dhavan":80}

Comments or Responses

Login to post response