Live data from Hacker News

A love letter to the CSV format

github.com

451–460 of 711 posts

Re: A love letter to the CSV format

#451
post #419
post #403

Earlier quoted context omitted.

Have you had to work with csv files from the wild much? I'm not being snarky but what you're talking about is night and day to what I've experienced over the years. There aren't vast numbers of different JSON formats. There's practically one and realistically maybe two. Headers are in each line, utf8 has never been an issue for me and quoting and escaping are well defined and obeyed. This is because for datasets, alm…

What's the problem with capital I?

https://superuser.com/questions/210027/why-does-excel-think-... says itks not capital I but “ID”.

Basically, Excel uses the equivalent of ‘file’ (https://man7.org/linux/man-pages/man1/file.1.html), sees the magic “ID”, and decides a SYLK file, even though .csv files starting with “ID” have outnumbered .SYLK files by millions for decades.

Re: A love letter to the CSV format

#453
post #417
post #415

I think for "untyped" files with records, using the ASCII file, (group) and record separators (hex 1C, 1D and 1E) work nicely. The only constraint is that the content cannot contain these characters, but I found that that is generally no problem in practice. Also the file is less human readable with a simple text editor. For other use cases I would use newline separated JSON. Is has most of the benefits as written in…

I agree that JSONL is the spiritual successor of CSV with most of the benefits and almost none of the drawbacks. It has a downside though: wherever JSON itself is used, it tends to be a few kilobytes at least (from an API response, for example). If you collect those in a JSONL file the lines tend to get verrrry long and difficult to edit. CSV files are more compact. JSONL files are a lot easier to work with though. L…

The drawbacks are quite substantial actually – uses much more data per record. For many cases it's a no-go.

Re: A love letter to the CSV format

#454
post #445
post #419

Earlier quoted context omitted.

What's the problem with capital I?

The byte for a capital I is the same as the start for an odd file format, slyk maybe? Excel has (or did if they finally fixed it) for years decided this was enough to assume the file (called .csv) cannot possibly be csv but must actually be slyk. It then parses it as such, and is shocked to find your slyk file is totally broken!

It sounds to me like as often the problem here is Excel, not CSV

Re: A love letter to the CSV format

#455
post #156

I've recently been developing a raspberry pi based solution which works with telemetry logs. First implementation used an SQLite database (with WAL log) – only to find it corrupted after just couple of days of extensive power on/off cycles. I've since started looking at parquet files – which turned out to not be friendly to append-only operations. I've ended up implementing writing events into ipc files which then pe…

> First implementation used an SQLite database (with WAL log) – only to find it corrupted after just couple of days of extensive power on/off cycles. Did you try setting `PRAGMA synchronous=FULL` on your connection? This forces fsync() after writes. That should be all that's required if you're using an NVMe SSD. But I believe most microSD cards do not even respect fsync() calls properly and so there's technically no…

Raspberry Pi uses microSD card. Just using fsync after every write would be a bit devastating, but batching might've worked ok in this case. Anyways, too late to check now.

Re: A love letter to the CSV format

#456
post #354

The post should at least mention in passing the major problem with CSV: it is a "no spec" family of de-facto formats, not a single thing (it is an example of "historically grown"). And omission of that meams I'm going to have to call this our for its bias (but then it is a love letter, and love makes blind...). Unlike XML or JSON, there isn't a document defining the grammar of well-formed or valid CSV files, and ther…

In fairness there are also several ambiguities with JSON. How do you handle multiple copies of the same key? Does the order of keys have semantic meaning? jq supports several pseudo-JSON formats that are quite useful like record separator separated JSON, newline separated JSON. These are obviously out of spec, but useful enough that I've used them and sometimes piped them into a .json file for storage. Also, encoding…

Internet JSON (RRC 7493) forbids objects to have members with duplicate names.

Re: A love letter to the CSV format

#457
post #142

Earlier quoted context omitted.

That mostly breaks down to "excel is intentionally stupid with csv files if you don't use the import function to open them" along with the normal "don't trust customer input without stripping or escaping it" concerns you'd have with any input.

Someone filed a bug report on a project I work on, saying that it was a security vulnerability that we don't prefix cell values with a single quote (') when the cell content contains certain values like an equal sign (=). They said this can cause Excel to evaluate the content and potentially run unsafe code. I responded that this was Excel's problem, not ours, and that nobody would assign a CVE to our product for suc…

The next version of CVSS needs to add a metric for these kind of bullshit non-vulnerabilities so that we can ignore them at source.

Re: A love letter to the CSV format

#458
post #280

Earlier quoted context omitted.

Any time you have a character with a special meaning you have to handle that character turning up in the data you're encoding. It's inevitable. No matter what obscure character you choose, you'll have to deal with it

Except we have all these low ASCII characters specifically for this purpose that don't turn up in the data at all. But there is, of course, also an escape character specifically for escaping them if necessary.

Even if you find a character that really is never in the data - your encoded data will contain it. And it's inevitable that someone encodes the encoded data again. Like putting CSV in a CSV value.

Re: A love letter to the CSV format

#459
post #433
post #428

Earlier quoted context omitted.

While CSV isn't exactly grammared or standardised like XML I think if it as more schema:d than JSON. There might be data corruption or consistency issues, but there is implicitly a schema: every line is exactly n fields, and the first line might contain field names. When a JSON API turns out to have optional fields it usually shows through trial and error, and unlike CSV it's typically not considered a bug you can ex…

JSON is not schema’d per se and intentionally so. There’s jsonschema which has better expressiveness than inference of a tabular schema, as it can reflect relationships.

Sure. I have yet to come across a data source with JSON Schema, I'll develop an opinion of it when I do.

Re: A love letter to the CSV format

#460
post #385

Earlier quoted context omitted.

I feel like YAML is a spiritual successor to the .ini, since it shares a notable ideal of simple human readability/writability.

Whenever I ask myself "should I use YAML?" I answer myself "Norway".

To be fair to YAML that's been solved in 1.2.

https://yaml.org/spec/1.2.2/#10212-boolean

Post reply on HN