javascript - Difference between JSON.stringify and JSON.parse

Published: 25 June 2023
on channel: Code Samples
180
3

#short
#javascript
#json
I have been confused over when to use these two parsing methods.
After I echo my json_encoded data and retrieve it back via ajax, I often run into confusion about when I should use JSON.stringify and JSON.parse.
I get [object,object] in my console.log when parsed and a JavaScript object when stringified.
$.ajax({
url: "demo_test.txt",
success: function(data) {
console.log(JSON.stringify(data))
/* OR */
console.log(JSON.parse(data))
//this is what I am unsure about?
}
});


On this page of the site you can watch the video online javascript - Difference between JSON.stringify and JSON.parse with a duration of hours minute second in good quality, which was uploaded by the user Code Samples 25 June 2023, share the link with friends and acquaintances, this video has already been watched 180 times on youtube and it was liked by 3 viewers. Enjoy your viewing!