Is there a crate that let me customize code style of printed YAML/JSON (indent and stuff)?

Sometimes I prefer JSON/YAML with 4 space indentation instead of 2. Sometimes I want all YAML arrays to be indented relative to its dictionary field (which was what the old version of serde_yaml did). And sometimes I want array with only less than 5 small numbers to be in one line.

to_string_pretty doesn't provide any configuration parameter.

For JSON, there's serde_json::PrettyFormatter::with_indent().

1 Like

serde_json provides a formatter trait which allows for full customization. Formatter in serde_json::ser - Rust

It does not seem like serde_yaml offers that. You might need to use a different crate.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.