So here is the thing: I am normally against using Ai tools in programming in generative manner. But I asked an agent to write one for me, because I could not solve it myself and could not find a solution looking in the internet. I disclosed in the comments for this function that it is “written” by an ai. But I don’t know how I can take that code and license it on my own terms, if I am not the copyright holder.

Its a small hobby CLI app for extreme niche use case. The tool itself is written in Rust and has yet to be finished and uploaded. Its working with a specific Json based data format.

The problem was, I needed a functionality to delete a specific named key from a list of serde_json::Value. And the simplest idea and solution I got was to first set each of these values for the source key to Value::Null and then delete each key/value pair with a null value. My code:

    pub fn remove_source_from_items(&mut self) {
        for item in self.data["items"].as_array_mut().unwrap() {
            item["source"] = Value::Null;
        }
        match &mut self.data["items"] {
            Value::Object(map) => {
                // Collect keys to remove first to avoid borrowing issues
                let keys_to_remove: Vec<String> = map
                    .iter()
                    .filter_map(|(k, v)| if v.is_null() { Some(k.clone()) } else { None })
                    .collect();

                for key in keys_to_remove {
                    map.remove(&key);
                }

                // Recursively process remaining values
                for value in map.values_mut() {
                    remove_null_values(value);
                }
            }
            Value::Array(arr) => {
                for item in arr.iter_mut() {
                    remove_null_values(item);
                }
            }
            _ => {}
        }
    }

remove_null_values(): However I could not figure out how to delete them in bulk and finally asked the Ai model to solve this for me. This is what it wrote and it does what it should do and it is performant too. It even set a few comments (but the top header comment is from me off course):

// Generated by local Ai:
//  Devstral Small 2507
//  24B, Q6_K
//  July, 2025
fn remove_null_values(value: &mut Value) {
    match value {
        Value::Object(map) => {
            // Collect keys to remove first to avoid borrowing issues
            let keys_to_remove: Vec<String> = map
                .iter()
                .filter_map(|(k, v)| if v.is_null() { Some(k.clone()) } else { None })
                .collect();

            for key in keys_to_remove {
                map.remove(&key);
            }

            // Recursively process remaining values
            for value in map.values_mut() {
                remove_null_values(value);
            }
        }
        Value::Array(arr) => {
            for item in arr.iter_mut() {
                remove_null_values(item);
            }
        }
        _ => {}
    }
}

Overall this answer was done in a few minutes on my Linux PC with RX 7600 8GB, by the model disclosed in the comment.

BTW, when I experimented I was close to this solution as well! But just could not figure it out. If anyone has a better solution, I am open for it. But this is going a bit over my head. This is my second attempt in using an Ai model and I feel ashamed of it. Because I should have spent the time to learn and do it myself instead. But here we are.