📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Learn more about JavaScript at https://www.javaguides.net/p/javascript-tutorial-with-examples.html
var user = { firstName : 'Ramesh', lastName : 'Fadatare', emailId : 'ramesh@gmail.com', age : 29 }
JSON.stringify(user)
console.log(JSON.stringify(user));
{"firstName":"Ramesh","lastName":"Fadatare","emailId":"ramesh@gmail.com","age":29}
JSON.stringify() Method - Detail Explanation
Syntax
JSON.stringify(value[, replacer[, space]])
Parameters
- value - This is a parameter is required. The value to convert to a JSON string.
- replacer - This parameter is optional. Either a function or an array used to transform the result. The replacer is called for each item.
- space - This parameter is optional. A String or Number object that's used to insert white space into the output JSON string for readability purposes.
JSON.stringify() Method Examples
var user = {
firstName : 'Ramesh',
lastName : 'Fadatare',
emailId : 'ramesh@gmail.com',
age : 29
}
JSON.stringify(user)
console.log(JSON.stringify(user));
{"firstName":"Ramesh","lastName":"Fadatare","emailId":"ramesh@gmail.com","age":29}
function replacer(key, value) {
// Filtering out properties
if (typeof value === 'string') {
return undefined;
}
return value;
}
var foo = {foundation: 'Mozilla', model: 'box', week: 45, transport: 'car', month: 7};
JSON.stringify(foo, replacer);
"{"week":45,"month":7}"
var foo = {foundation: 'Mozilla', model: 'box', week: 45, transport: 'car', month: 7};
JSON.stringify(foo, ['week', 'month']);
"{"week":45,"month":7}"
JSON.stringify({ a: 2 }, null, ' ');
"{
"a": 2
}"
JSON.stringify({ uno: 1, dos: 2 }, null, '\t');
"{
"uno": 1,
"dos": 2
}
Comments
Post a Comment
Leave Comment