Convert JS object to JSON string

If I defined an object in JS with:

var j=
{
name:binchen
};
 

How can I convert the object to JSON? The output string should be:

'
{
name:binchen
}' 
Text Copied From stackoverflow.com
on : Fri, Nov 12, 2010 Views : 1171244

Accepted Answer

All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:

var j=
{
name:binchen
};
 JSON.stringify(j);
 
// '
{
name:binchen
}' 
Text Copied From stackoverflow.com
on : Fri, Nov 12, 2010

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp