node json stringify

const obj = {
  name: 'John',
  age: 30,
  city: 'New York'
};

const jsonString = JSON.stringify(obj);
console.log(jsonString);
  1. Declare an object named obj with three key-value pairs: name with the value 'John', age with the value 30, and city with the value 'New York'.

  2. Use JSON.stringify() to convert the obj object into a JSON string representation. This method creates a JSON string from the provided object.

  3. Store the JSON string generated from the obj object in the variable jsonString.

  4. Print the jsonString variable to the console using console.log(). This displays the JSON string representation of the obj object.