DEV Community

Discussion on: YAML (and JSONC) failed as a data transfer format with comments

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

But for YAML, machines cannot preserve comments?

Collapse
 
stevepryde profile image
Steve Pryde

I'm not sure I understand what you mean. YAML is not good as a serialization format. It is for configuration only. The comments are only for humans.

I do wish JSON allowed comments, however. This is the main reason why I prefer YAML over JSON for configuration files that are intended to be edited by humans.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt

yaml.dump(yaml.load($string)), and comments are lost.

Thread Thread
 
stevepryde profile image
Steve Pryde

Ah ok. Yes I can see why this would be annoying.

I believe there are yaml parsers that do preserve comments but probably not for every language.