Enable toJSON function to return different types