-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document setIn() should work if document contents are empty #174
Comments
I'm not sure that I understand the question here. The example above should just work. Perhaps if you could give an example which fails to work as intended? |
Above example doesn't work, if the those properties doesn't exist in yaml file.
In my case yaml is updated by multiple teams, if there is already a key for Also i tried doing this, but getting the same error
|
Ah, I think I see now. When you're parsing empty input, it's not possible to determine what shape those contents are expected to have. A YAML document is not limited to having a key-value mapping at its root. So what you should probably do is that once you've parsed the config file into a YAML document, check that it's a map, and if it's not, assign a map to the contents. After that, the
For the particular case where contents are empty, it would make sense for the root mapping to be auto-generated because there's no pre-existing value to override. Especially as that's what |
Also it's not necessary that this YAML file will be empty and not sure how above snippet solve my problem. eg. Existing YAML Doc
So my end goal here is to update the value of property_1 but to set this property i will have to check if parents properties are there. This can be easily achieved using Parse and Stringify but i also want to preserve comments and line breaks here. |
This should now be fixed. There were in fact two separate bugs here:
|
my yaml file may or may not have keys and values, if doesn't have keys then i want create it. I think this issue documented as well but is there any way to achieve this.
conf.yml
The text was updated successfully, but these errors were encountered: