Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this valid YAML?

So for my text parsing in C# question, I got directed at YAML. I'm hitting a wall with this library I was recommended, so this is a quickie.

heading:
 name: A name
 taco: Yes
 age: 32

heading:
 name: Another name
 taco: No
 age: 27

And so on. Is that valid?

like image 740
Bernard Avatar asked Nov 27 '22 19:11

Bernard


1 Answers

Partially. YAML supports the notion of multiple consecutive "documents". If this is what you are trying to do here, then yes, it is correct - you have two documents (or document fragments). To make it more explicit, you should separate them with three dashes, like this:

---
heading:
 name: A name
 taco: Yes
 age: 32
---
heading:
 name: Another name
 taco: No
 age: 27

On the other hand if you wish to make them part of the same document (so that deserializing them would result in a list with two elements), you should write it like the following. Take extra care with the indentation level:

- heading:
  name: A name
  taco: Yes
  age: 32
- heading:
  name: Another name
  taco: No
  age: 27

In general YAML is concise and human readable / editable, but not really human writable, so you should always use libraries to generate it. Also, take care that there exists some breaking changes between different versions of YAML, which can bite you if you are using libraries in different languages which conform to different versions of the standard.

like image 160
Grey Panther Avatar answered May 10 '23 23:05

Grey Panther