by @saigowthamr

How to convert a JavaScript object into a JSON string

Home » javascript » How to convert a JavaScript object into a JSON string

To convert a JavaScript object to json string we can use the JSON.stringfy() method by passing object as an argument to it.

Here is an example that converts the user object to a JSON string.

const user  = {
    name: "coach",
    age: 12,
    active:false
}

const userString  = JSON.stringify(user);

console.log(userString);

Output:

"{"name":"coach","age":12,"active":false}"

Best Web Development courses