Given the following JsonValue:
let mut schema = json!({
"level": "strict",
"rule": {}
});
Where we would dynamically insert values to this JsonValue
let value: json!({
"type": property.r#type,
"minLength": property.min_length,
"maxLength": property.max_length,
"enum": property.r#enum
});
schema["rule"]
.as_object_mut()
.unwrap()
.insert(
String::from(property.name),
value
);
// Struct for Property
#[derive(Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaDocumentProperty
{
pub name: String,
pub r#type: Option<String>,
pub min_length: Option<u32>,
pub max_length: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#enum: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<SchemaDocumentPropertyArray>
}
The current output is the following where minLength
, maxLength
and enum
are None:
{
"type": "string",
"minLength": null,
"maxLength": null,
"enum": null
}
My desired output:
{
"type": "string"
}
I want to omit all of the None values from the JsonValue macro.
.as_object_mut().unwrap().insert(k, v)
only accepts JsonValue onv
. The following is thrown: mismatched types expected enumserde_json::Value
, found structSchemaDocumentProperty
rustc (E0308) – Hallerson