jhorstmann commented on a change in pull request #1205:
URL: https://github.com/apache/arrow-rs/pull/1205#discussion_r787618284



##########
File path: arrow/src/json/writer.rs
##########
@@ -178,31 +178,29 @@ pub fn array_to_json_array(array: &ArrayRef) -> 
Vec<Value> {
         DataType::UInt64 => primitive_array_to_json::<UInt64Type>(array),
         DataType::Float32 => primitive_array_to_json::<Float32Type>(array),
         DataType::Float64 => primitive_array_to_json::<Float64Type>(array),
-        DataType::List(_) => as_list_array(array)
+        DataType::List(_) => Ok(as_list_array(array)
             .iter()
             .map(|maybe_value| match maybe_value {
-                Some(v) => Value::Array(array_to_json_array(&v)),
+                Some(v) => Value::Array(array_to_json_array(&v).unwrap()),

Review comment:
       Since this is inside a closure, that closure needs to have a return type 
of `Result` in order to use the `?` operator. You can achieve that by wrapping 
the Value in `Ok` like this:
   
   ```
           DataType::List(_) => as_list_array(array)
               .iter()
               .map(|maybe_value| {
                match maybe_value {
                   Some(v) => Ok(Value::Array(array_to_json_array(&v)?)),
                   None => Ok(Value::Null),
               }})
               .collect(),
   ```
   
   The `collect` at the end is able to create a `Result<Vec<X>>` from that 
`Iterator<Result<X>>`. The type is inferred based on the method return type. 
Often you would have to specify that explicitly like 
`.collect::<Result<Vec<_>>()`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to