serde-yaml icon indicating copy to clipboard operation
serde-yaml copied to clipboard

help parsing YAML with keys as with hyphens

Open mzagrabe opened this issue 2 years ago • 1 comments

Greetings,

I have YAML files such as:

foo-bar: baz

I'd like to use serde-yaml to parse into:

struct FooBar {
    foo_bar: String,
}

Do you know if there is some simple/elegant way to deserialize this mismatch between hyphens and underscores?

Thanks for the help!

-m

mzagrabe avatar Sep 27 '22 17:09 mzagrabe

struct FooBar {
    #[serde(rename="foo-bar")]
    foo_bar: String,
}

should work

jhoobergs avatar Oct 01 '22 19:10 jhoobergs