- Instant help with your JavaScript coding problems

Convert object to JSON string in JavaScript

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

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?"