Implement toJSON (which is used by JSON.stringify)