dart-lang / yaml_edit

A library for YAML manipulation with comment and whitespace preservation.
https://pub.dev/packages/yaml_edit
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

no way to add a key in a blank yaml file #32

Closed animeshjain closed 1 year ago

animeshjain commented 1 year ago

Example:

final doc = YamlEditor('');
doc.update(['bar'], 'val2');
print(doc);

fails with Invalid path: [bar]. Scalar null does not have key bar

whereas..

final doc = YamlEditor('foo: val1');
doc.update(['bar'], 'val2');
print(doc);

works fine

jonasfj commented 1 year ago

I think you need to add an object, when the root object is null.