clj-yaml icon indicating copy to clipboard operation
clj-yaml copied to clipboard

Support multiple yaml documents in the same file

Open ieugen opened this issue 3 years ago • 6 comments

Hello,

How can I read multiple yaml documents from a single file ? Is that supported?

In yaml, you can write multiple documents in a single file by separating documents with a line that has only ---

In SnakeYaml, this is done using loadAll https://www.baeldung.com/java-snake-yaml#multiple-documents

ieugen avatar Nov 02 '21 11:11 ieugen

Perhaps as a temporary workaround you can slurp the file, split it on #"^---$" and then use parse-string on each chunk.

borkdude avatar Nov 02 '21 11:11 borkdude

I think we could have load-all variants of the functions we already have. E.g. parse-string-all.

Or: we could have an option :all true in which case it defers to the loadAll variants.

/cc @slipset @marcomorain

borkdude avatar Nov 02 '21 11:11 borkdude

I'll defer to what @marcomorain has to say on this topic, as I'm not using, only maintaining this library.

slipset avatar Nov 02 '21 12:11 slipset

@slipset @marcomorain FYI As this library is part of babashka, I wouldn't mind to get involved as a contributor to ensure this library is kept up to date.

borkdude avatar Nov 02 '21 12:11 borkdude

I'd happily review a PR for this.

FWIW, adding a new-all vars would be my preferred approach, rather than adding options.

I would not want to a single load function that returns different types depending on the value of an optional argument – that makes reading and statically analysing the code much more difficult.

marcomorain avatar Nov 02 '21 12:11 marcomorain

@marcomorain I agree!

borkdude avatar Nov 02 '21 12:11 borkdude

Fixed by 7254f6189c7e07aa288c4fcc195bf9c9d4e68305

lread avatar Sep 20 '22 23:09 lread