/// Parse a `metadata` definition from a JSON representation.
/// The JSON can either be an Object or an Array of Objects.
Parse a `metadata` definition from a JSON representation.
The JSON can either be an Object or an Array of Objects.
Parse a ` metadata ` definition from a JSON representation . The JSON can either be an Object or an Array of Objects .
fn from_metadata(json: &Value) -> Result<HashMap<String, String>> {
    match json {
        Value::Array(_) => {
            let mut hashmap = HashMap::new();
            let values: Vec<MetadataKeyValue> = serde_json::from_value(json.clone())?;
            for meta in values {
                hashmap.insert(meta.key.clone(), meta.value);
            }
            Ok(hashmap)
        }
        Value::Object(md) => md
            .iter()
            .map(|(k, v)| {
                if let Value::String(v) = v {
                    Ok((k.to_string(), v.to_string()))
                } else {
                    Err(ArrowError::Schema(
                        "metadata `value` field must be a string".to_string(),
                    ))
                }
            })
            .collect::<Result<_>>(),
        _ => Err(ArrowError::Schema(
            "`metadata` field must be an object".to_string(),
        )),
    }
}
fn from_metadata ( json : & Value ) -> Result < HashMap < String , String > > { match json { Value :: Array ( _ ) => { let mut hashmap = HashMap :: new ( ) ; let values : Vec < MetadataKeyValue > = serde_json :: from_value ( json . clone ( ) ) ? ; for meta in values { hashmap . insert ( meta . key . clone ( ) , meta . value ) ; } Ok ( hashmap ) } Value :: Object ( md ) => md . iter ( ) . map ( | ( k , v ) | { if let Value :: String ( v ) = v { Ok ( ( k . to_string ( ) , v . to_string ( ) ) ) } else { Err ( ArrowError :: Schema ( " " . to_string ( ) , ) ) } } ) . collect :: < Result < _ > > ( ) , _ => Err ( ArrowError :: Schema ( " " . to_string ( ) , ) ) , } }
Parse a `metadata` definition from a JSON representation.
Parse a ` metadata ` definition from a JSON representation .
json
&Value