-
-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Description
| fn wrap_value(value: Value) -> Value { |
I'm trying to understand the purpose of this function. AFAICT this is replacing any empty map inside a Value::Object with a Map::new(). However, my impression is that these should be equivalent... am I missing something here?
fn wrap_value(value: Value) -> Value {
match value {
// If the value is an object, check if it's empty
Value::Object(map) => {
if map.is_empty() {
// Wrap empty map as an empty JSON object
Value::Object(Map::new())
} else {
// Recursively wrap each key-value pair in the map
Value::Object(map.into_iter().map(|(k, v)| (k, wrap_value(v))).collect())
}
}
// If the value is an array, recursively wrap each element
Value::Array(arr) => Value::Array(arr.into_iter().map(wrap_value).collect()),
// If the value is null, return it as is
Value::Null => Value::Null,
// For primitive values, return them as is
other => other,
}
} Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels