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:
The most popular way is below:
var obj = {name: "Martin", age: 30, country: "United States"}; // Converting JS object to JSON string var json = JSON.stringify(obj); console.log(json);