📘 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
Usiing JSON.parse() Method
var text = JSON.parse( '{ "firstName" : "Ramesh", "lastName" : "Fadatare", "emailId" : "ramesh@gmail.com", "age" : "29" }');
console.log(text);
{firstName: "Ramesh", lastName: "Fadatare", emailId: "ramesh@gmail.com", age: "29"}
JSON.parse() Method - Detail Explanation
Syntax
JSON.parse(text[, reviver])
Parameter Values
- text - This is a required field. A string is written in JSON format
- reviver function - This parameter an optional. A function used to transform the result.
JSON.parse() Method Examples
var text = JSON.parse( '{ "firstName" : "Ramesh", "lastName" : "Fadatare", "emailId" : "ramesh@gmail.com", "age" : "29" }');
console.log(text);
{firstName: "Ramesh", lastName: "Fadatare", emailId: "ramesh@gmail.com", age: "29"}
/*replace the value of "city" to upper case:*/
var text = '{ "name":"John", "age":"39", "city":"New York"}';
var obj = JSON.parse(text, function (key, value) {
if (key == "city") {
return value.toUpperCase();
} else {
return value;
}
});
console.log(text);
{ "name":"John", "age":"39", "city":"New York"}
JSON.parse('{}'); // {}
JSON.parse('true'); // true
JSON.parse('"foo"'); // "foo"
JSON.parse('[1, 5, "false"]'); // [1, 5, "false"]
JSON.parse('null'); // null
Comments
Post a Comment
Leave Comment