JSON.stringify uses the toJSON method.
You can specify it for your object or, in your case, redefine it:
ClientRect.prototype.toJSON = function(){ return { top: this.top } } JSON.stringify(document.body.getBoundingClientRect()) "{"top":-583}"
source share