json icon indicating copy to clipboard operation
json copied to clipboard

produce json without null values

Open mothsART opened this issue 1 year ago • 1 comments

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 ?

mothsART avatar Sep 03 '22 18:09 mothsART

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());

kangalio avatar May 23 '23 17:05 kangalio