json
json copied to clipboard
produce json without null values
I tried to convert json with null values to a format without it.
let json_value: Value = serde_json::from_str("{ \"key\": \"value\", \"null_value\": null }")?;
println!("{}", serde_json::to_string(&json_value)?);
must be print :
{ "key": "value" }
How can i do that without knowing json structure ?
Loop over the key-value pairs and remove those with a null.
You can do that for example with Map's retain method: map.retain(|_key, value| !value.is_null());