-1

I am considering using YAML for storing chronological data in the following way:

- entrydate: 5:55 AM 1/1/2013
  title: blog post 1
  tags: [yaml, json]
  description: what have i learned today 1
  location: scottsdale
- entrydate: 5:55 AM 1/2/2013
  title: blog post 2
  tags: [general,software-development]
  description: what have i learned today 2
  location: scottsdale

This YAML document will get updated daily by a C# application which collects the data and at the end of week/month a Python program calculates some metrics about the blogging progress .

This answer to the question Is this valid YAML? suggests that YAML supports the notion of partial documents and if formatted as above each blog entry would considered a separate entity. Now I am concerned about two things.

  1. Would YAML parsers be able to identify each entity (or blog entry , in this case) by the entrydate as it is in the top of each element? I ask this because in both yamllint and online yaml parser, the parsed output was reordered and the entrydate was lumped in together with other items.
  2. Is YAML a complete overkill for this task? I feel it is apt, because the data stored would be in human readable format and if need be I could edit the document by hand easily.

PS: I considered JSON for this, but I felt YAML is too easy on the eyes.

Community
  • 1
  • 1
Animesh
  • 4,926
  • 14
  • 68
  • 110

1 Answers1

3

Would YAML parsers be able to identify each entity (or blog entry , in this case) by the entrydate as it is in the top of each element? I ask this because in both yamllint and online yaml parser, the parsed output was reordered and the entrydate was lumped in together with other items.

I'm not entirely clear what you're asking here. This is valid YAML, and it will result in a list of dictionaries. Each dictionary will have several keys (description, entrydate, locations, tags, title). Once you have read the data in with a YAML parser you can reference any of those keys; which one appears "first" in the output is typically unimportant. Generally, dictionary implementations do no preserve the order in which keys are added.

The ordering of the list will be preserved, so the entry with entrydate = 5:55 AM 1/1/2013 will always be the first in the list (as long as it is the first entry in the file).

Is YAML a complete overkill for this task? I feel it is apt, because the data stored would be in human readable format and if need be I could edit the document by hand easily.

You're trying to store structured data in a simple, readable format. That's what YAML is for.

larsks
  • 277,717
  • 41
  • 399
  • 399