Skip to content

Commit cfd6989

Browse files
author
Devdutt Shenoi
authored
Merge branch 'main' into storage-share
2 parents 8c7ab16 + 73d6f8c commit cfd6989

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/utils/json/flatten.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,11 @@ pub fn has_more_than_four_levels(value: &Value, current_level: usize) -> bool {
335335

336336
// Converts a Vector of values into a `Value::Array`, as long as all of them are objects
337337
pub fn convert_to_array(flattened: Vec<Value>) -> Result<Value, JsonFlattenError> {
338-
let mut result = Vec::new();
339-
for item in flattened {
340-
let mut map = Map::new();
341-
let Some(item) = item.as_object() else {
342-
return Err(JsonFlattenError::ExpectedObjectInArray);
343-
};
344-
for (key, value) in item {
345-
map.insert(key.clone(), value.clone());
346-
}
347-
result.push(Value::Object(map));
338+
if flattened.iter().any(|item| !item.is_object()) {
339+
return Err(JsonFlattenError::ExpectedObjectInArray);
348340
}
349-
Ok(Value::Array(result))
341+
342+
Ok(Value::Array(flattened))
350343
}
351344

352345
#[cfg(test)]

0 commit comments

Comments
 (0)