faster toJSON function