- Instant help with your JavaScript coding problems

Convert object to JSON string in JavaScript

How to convert object to JSON string in JavaScript?
let user = {id:1, username:"john", creationDate:"2020-11-24", active:true};
let jsonStr = JSON.stringify(user);

The built in JSON object in JavaScript contains methods to handle JSON related tasks. The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

Share "How to convert object to JSON string in JavaScript?"