
Ask HN: File format like JSON/YAML that allows tables to be defined like CSV? - anderspitman
Whenever I take a dataset from a spreadsheet&#x2F;CSV and convert it over to something like JSON or YAML, it&#x27;s always annoying to have to include every attribute in every record, rather than just having the header row like a spreadsheet. Extra annoying if you ever have to rename an attribute I&#x27;ve even written several one-off parsers to convert between the two. This got me wondering if there&#x27;s a file format similar to YAML but where you can embed a table in a CSV&#x2F;TSV-like format to improve readability if desired.
======
grandchild
Maybe I'm punching in the screw with only my hammer here, but what's wrong
with combining block- and flow style in YAML?

    
    
      ---
      columns: [id, name, age]
      data:
        - [1, "Alice", 27]
        - [2, "Bob", 26]
        - [3, "Carol", 45]

~~~
anderspitman
This would certainly work as a storage format, but would require custom
parsing. It would be nice to have a format that automatically expanded that
into a sequence of maps.

------
cocktailpeanuts
Most CSV parsers include this feature by default. Basically you can specify in
the setting whether to regard the first row as a special row for attribute
names or not.

So the answer is you can just use CSV like you use, but just need to use the
right parser and turn on the right options when parsing to auto-assign
attribute names.

~~~
anderspitman
Right. I'm looking for embedding functionality like that in a richer object
format like YAML. So you could still use the other datatypes and functionality
YAML offers, but also have succinct table syntax.

