Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

If I have an object like this:

var j={"name":"Virat"};

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

'{"name":"Virat"}'

 

1 Answer

0 votes
by (13.1k points)

You can convert a js object JSON string by using JSON.stringify() function. For example:

Var obj={‘name’:"Virat"};

console.log(JSON.stringify(obj));

Interested in Web Development? Check out this web developer certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...