Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: File format like JSON/YAML that allows tables to be defined like CSV?
10 points by apitman on Oct 15, 2017 | hide | past | favorite | 5 comments
Whenever I take a dataset from a spreadsheet/CSV and convert it over to something like JSON or YAML, it'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've even written several one-off parsers to convert between the two. This got me wondering if there's a file format similar to YAML but where you can embed a table in a CSV/TSV-like format to improve readability if desired.



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]


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.


And of course you can do that same format with JSON output - have a columns array and a data array.


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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: