An object may provide method toJSON for to-JSON conversion. JSON.stringify automatically calls it if available
let room = {
  number: 23,
  toJSON() {
    return this.number;
  }
};

let meetup = {
  title: "Conference",
  room
};

// document.write(JSON.stringify(room));
document.write(JSON.stringify(meetup));
Result of the code above is the following
{"title":"Conference","room":23}
by Valeri Tandilashvili
4 years ago
JSON
JavaScript
JSON Tutorial
1
Pro tip: use ```triple backticks around text``` to write in code fences