How do I convert a JS object to a JSON string?
var o = { name: "a", id:5};
var sz = //???
alert('The json will look like ' + sz);
I would like to do it natively if possible, or using jQuery if not.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are looking for the
JSON.stringifymethod:This method is part of the ECMAScript 5 Standard, and almost every browser includes it.
For older browsers and IE < 8, you can include the json2.js file.