tobozo / YAMLDuino

YAML <=> JSON converter for ESP32, ESP8266, RP2040 and possibly other devices
Other
42 stars 2 forks source link

serialize comments to yaml #14

Open marnikvd opened 1 year ago

marnikvd commented 1 year ago

Hello,

The reason why I prefer to use YAML is the ability to use comments. So my question is : Since JSON doesn't support comments, how can I serializeYml() with comments?

I know you can deserialize a YAML with comments to a JsonObject, but I guess you loose the comments.

I want to :

  1. read a YAML file (with comments in it)
  2. change the content
  3. write back the YAML with the changes and the comments
tobozo commented 1 year ago

Hey thanks for your feedback :+1:

Keeping comments between editions seems impossible as they're implicitely dumped by the scanner.

The topic is still open, missing features are whitespace preservation and comment token/event handling.

Moreover, editing YAML without ArduinoJson requires a libyaml C++ wrapper with a real iterator and accessors.

Good news is pure-libyaml manipulation was on the roadmap of this project, so I can go halfway and integrate this C++ libyaml wrapper as a start, then see what happens to existing comments after editing the yaml.

Going any further will mean contributing the upstream libyaml project, and the test suite is really scary :)

[edit] libyaml-cpp didn't help, the problem is in yaml design and libyaml minimalism.

image

more info in this SO post