Document Add/Set/Delete values deep in the YAML? #355
-
If I have a Document (doc) that represents the above YAML, I want to be able to add a key/value pair next to key1, like this:
To do this, I'd think I could do
Is there a way to do deep adds/sets/deletes? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Here's the part where I sort of answer my own question after doing some more playing around:
However, if I wanted to set 'a.d.e.key3' like:
This comes out looking like:
|
Beta Was this translation helpful? Give feedback.
-
This should work, at least with # src
a:
b:
c:
key1: value1 import { parseDocument } from 'yaml'
const doc = parseDocument(src)
doc.setIn(['a','b','c','key2'], 'value2')
doc.setIn(['a','d','e','key3'], 'value3') # doc.toString()
a:
b:
c:
key1: value1
key2: value2
d:
e:
key3: value3 |
Beta Was this translation helpful? Give feedback.
This should work, at least with
yaml@next
?