Skip to content

Purpose of internal function wrap_value #47

@Imberflur

Description

@Imberflur

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, 
     } 
 } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions