We have many options for serialization formats – when do we use what? A few thoughts prompted by this discussion over at the LVGL community.
I generally don’t like XML for things like config, but I like it for a UI for several reasons:
- UI’s tend to be deeply nested. Therefore the closing tags in XML, while harder to write, make it much easier to read and figure out where you are. It is very easy to get lost in deeply nested JSON. For most programming tasks, we want to optimize for easy reading, not writing.
- It is more similar to HTML, which many people are familiar with for UIs
YAML and TOML are nice for hand-edited configs, but these don’t tend to be deeply nested.
JSON is good for machine-generated and machine-read configs/data/message payloads that are only occasionally read by a human. However, the nesting complexity of these payloads is relatively small compared to a UI.
HTML has won in UIs, even after untold attempts in our industry to do something else. There are likely good reasons – don’t ignore this.