How to covert JavaScript object to JSON string?


This short article is about how to convert a JavaScript object into a JSON string.

In JavaScript, to covert an object into a JSON string we can use the JSON.stringify() method.

The JSON.stringify() method is used to take an object and transform it into a JSON string.

Syntax:

JSON.stringify(obj)

Let's check the use of JSON.stringify() with an example.

let obj = { name: 'Johnny', id: 5554, city: 'London' }
const jsonStr = JSON.stringify(obj)

console.log(jsonStr)

Output:

'{"name":"Johnny","id":5554,"city":"London"}'

Related Topics:

Difference Between JSON.Stringify() And JSON.Parse() In JSON

How to convert a JSON string into a JavaScript object

Beautify or pretty print JSON programmatically in JavaScript


💾 Recommended Articles