Sometimes, we want to turn TypeScript object into JSON string.
In this article, we’ll look at how to turn TypeScript object into JSON string.
How to turn TypeScript object into JSON string?
To turn TypeScript object into JSON string, we can use the JSON.stringify
method.
For instance, we write
const jsObj = { employee: { name: "John", age: 30, city: "New York" } };
const jsonString = JSON.stringify(jsObj);
console.log(jsonString);
to call JSON.stringify
with the jsObj
object to convert it to a JSON string.
Conclusion
To turn TypeScript object into JSON string, we can use the JSON.stringify
method.