Working with JSON, TOML and CSV
serde is in almost every Rust project that talks to anything, and the interesting part is never
the happy path. It is the API that renamed a field, the optional key that is missing, the enum that
arrives in four different shapes.
Each article here is one of those problems, with the derive attributes that fix it.
Articles
Section titled “Articles”- How to deserialize JSON into a structserde derive, and the rename you need when field names differ
- How to serialize a struct to JSONto_string versus to_string_pretty, and skipping None
- How to rename JSON fields with serderename, rename_all, and the API you cannot change
- How to handle a missing field in JSONOption, default, and the difference between the two
- How to serialize an enum with serdefour representations, and how to pick one
- How to read a JSON config fileserde, and what a schema change breaks
- How to parse a TOML config filetoml plus serde, and defaults that merge
- How to read a CSV file into structsserde, and headers that do not match
- How to write a CSV file from structsthe writer, and quoting you did not expect
- How to read a YAML fileserde_yaml, and the two YAML traps
- How to parse a query stringpercent-encoding, and the space that becomes a plus