json icon indicating copy to clipboard operation
json copied to clipboard

How to ignore the "$schema" property?

Open wcarmon opened this issue 2 years ago • 1 comments
trafficstars

JSON support "$schema" property.

As defined here: https://json-schema.org/understanding-json-schema/reference/schema.html?highlight=schema#id4

How can I get serde-json to ignore that field? (or map it to a string which I can ignore)

wcarmon avatar Dec 27 '22 20:12 wcarmon

serde ignores unknown fields by default. Nothing else needs to be done. If you want to capture the value as a string, for example because you need to serialize it again, you can use the rename attribute:

#[derive(serde::Serialize, serde::Deserialize)]
struct Foo {
	#[serde(rename = "$schema")]
	_schema: String,
}

jonasbb avatar Feb 25 '23 22:02 jonasbb