Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Handle Duplicated Keys in serde_yaml in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. The YAML specification does not forbid duplicated keys.

  2. serde-yaml ignores duplicated keys except the last one silently, by default. To overwrite this behavior, you have to define your own struct and use the tag serde_with::rust::maps_duplicate_key_is_error .

    dtolnay/serde-yaml#150

    https://users.rust-lang.org/t/how-can-i-handle-duplicate-fields-when-specifying-multiple-aliases-using-serde/46426