Skip to content

How could join two YAML document? #218

Closed Answered by eemeli
gixlg asked this question in Q&A
Dec 30, 2020 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

A couple of things going on here.

  1. Semantically, a YAML document can't contain another YAML document. What you're really wanting to do is to merge the root level mapping of the newStaff document with the value of lev2.
  2. The add() method only adds one value to the collection, so in this case you're adding a pair with the document as a key and an empty value to lev2.
  3. The stringifier somehow missed the newline in the inner document's string value, which is surprising. That's a bug that I ought to fix, but it won't really help you.

To get the results you want, iterate through newStaff.contents.items and add() each separately to lev2. You'll also need to add the trailing comment separately, if…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gixlg
Comment options

@eemeli
Comment options

Answer selected by eemeli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #218 on December 30, 2020 10:15.