News for hackers. Stuff that matters.
Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @11:25AM (#28222491)
You're comparing CSVs to other spreadsheet document formats. But a CSV is not a spreadsheet. A CSV is raw data. (It's data that is restricted to a shape that enables it to be easily imported into a spreadsheet—but data nevertheless.) As such, it should be compared to other data formats—e.g. YAML, JSON Lines, etc.

These other data formats all win on your #2 against CSV, as CSV is actually horrible at parse-time vs. other data formats — the fact that both of its separators (newlines and commas) can appear as-is inside column values, with a different meaning, if those column-values are quoted, means that there's no way to parallelize CSV processing, because there's no way to read-ahead and "chunk" a CSV purely lexically. You actually need to fully parse it (serially), and only then will you know where the row boundaries are. If you've ever dealt with trying to write ETL logic for datasets that exist as multi-GB CSV files, vs. as multi-GB any-other-data-format files, you'll have experienced the pain.

> The new format should not be grossly larger than the one it is replacing.

Self-describing formats like JSON Lines are big... but when you compress them, they go back to being small. General-purpose compressors like deflate/LZMA/etc. are very good at shearing away the duplication of self-describing rows.

As such, IMHO, the ideal format to replace ".csv" is ".jsonl.gz" (or, more conveniently, just ".jsonl" but with the expectation that backends will offer Transport-Encoding and your computer will use filesystem compression to store it — with this being almost the perfect use-case for both features.)

-----

There's also Avro, which fails your point #1 (it's a binary format) but that binary format is a lossless alternate encoding of what's canonically a JSON document, and there are both simple CLI tools / and small, free, high-quality libraries that can map back and forth between the "raw" JSON document and the Avro-encoded file. At any time, you can decode the Avro-encoded file to text, to examine/modify it in a text editor.

The data-warehouse ecosystem already standardized on Avro as its data interchange format. And spreadsheets are just tiny data warehouses. So why not? ;)

Re:Time to retire the CSV? by jerf on Wednesday August 18, 2021 @12:40PM (#28223728)
"Self-describing formats like JSON Lines are big... but when you compress them, they go back to being small."

For CSV file replacements, I'd expect something like "one JSON array per line, all values must be JSON scalars". In that case, it's not much larger than a CSV, especially one using quotes already for string values.

But this demonstrates the problem with JSON for CSV, I suppose. Is each line an object? Is it wrapped in a top-level array or not? If it is objects, do the objects have to be one line? If it is an object, where do we put field order? The whole problem we're trying to solve with CSV is that it's not a format, it's a family of formats, but without some authority coming in and declaring a specialized JSON format we end up with a family of JSON formats to replace CSV as well. I'd still say it's a step up; at least the family of JSON formats is unambiguously parseable and the correct string values will pop out. But it's less of a full solution than I'd like.

(It wouldn't even have to be that much of an authority necessarily, but certainly more than "The HN user named jerf declares it to be thus." Though I suppose if I registered "csvjson.org" or some obvious variant and put up a suitably professional-looking page that might just do the trick. I know of a few other "standards" that don't seem to be much more than that. Technically, even JSON itself wasn't much more than that for a lot of its run, though it is an IETF standard now.)

Re:Time to retire the CSV? by turtles_ on Wednesday August 18, 2021 @01:47PM (#28224689)
Indeed, this has already been done: http://ndjson.org/

To be fair it's not an objectionable format. Using line breaks to separate objects makes it streamable, and you don't need to enclose the whole thing in an array to make it a valid JSON document.

Re:Time to retire the CSV? by jerf on Wednesday August 18, 2021 @03:49PM (#28226229)
That is not quite a CSV replacement. I use it for things with objects and stuff all the time. To be a CSV replacement you really need to add that each line must be a JSON array, and that it can only have scalars in it (no sub-arrays or objects). That would be a decent enough replacement for CSV itself. Not perfect, but the CSV "standard" is already a nightmare at the edge anyhow and honestly a lot of it can't be fixed anyway, so, this is probably as good as it could get.
Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @06:52PM (#28228148)
> that it can only have scalars in it (no sub-arrays or objects)

I see CSV files that contain JSON arrays/objects in their fields all the time. Mainly from exporting Postgres tables that contain json/jsonb-typed columns. Are you saying that these aren't valid CSVs?

Re:Time to retire the CSV? by zerocrates on Thursday August 19, 2021 @12:01AM (#28230195)
They're saying that a CSV equivalent should be strictly 2-dimensional, with "flat" values.

Such a format could contain arbitrary JSON in a "cell", but simply as text, in the same way as putting the same data in a CSV.

Re:Time to retire the CSV? by shaftoe on Thursday August 19, 2021 @07:20AM (#28232499)
These are strings containing JSON
Re:Time to retire the CSV? by da_chicken on Wednesday August 18, 2021 @01:04PM (#28224120)
> But this demonstrates the problem with JSON for CSV, I suppose. Is each line an object?

How is that not a problem with every data serialization format? It does me no real good if I have an XML schema and a corresponding file. If I don't know what those elements and attributes represent I'm not really any better off.

It's not like JSON or XML can meaningfully be marshaled back into objects for use generically without knowledge of what is represented. There are generic JSON and XML readers that allow you to parse the data elements sure, but so, too, do generic CSV readers like C#'s CsvHelper or Python's csv. In all cases you have to know what the object turns into in the application before the serialized data is useful.

And, yes, CSV has slightly differing formats, but so does JSON. Date formats are conventionally ISO 8601, but that's not in the spec. That's why Microsoft got away with proprietary date formats in System.Text.Json. XML isn't really any better.

Re:Time to retire the CSV? by cpx86 on Wednesday August 18, 2021 @04:26PM (#28226634)
> That's why Microsoft got away with proprietary date formats in System.Text.Json.

What's proprietary in it? It follows ISO 8601-1:2019 and RFC 3339 according to the docs.

Re:Time to retire the CSV? by da_chicken on Wednesday August 18, 2021 @05:20PM (#28227331)
Sorry, that should be System.Runtime.Serialization.Json. System.Text.Json is the newer class that replaced it.

In .Net Framework 4.6 and earlier, the only built-in JSON serializer in the .Net Framework was System.Runtime.Serialization.Json.DataContractJsonSerializer.

You can still see it. If you're on Windows 10, run Windows Powershell v5.1 and run:

  Get-Item C:\Windows\System32\notepad.exe | Select-Object -Property Name, LastWriteTime | ConvertTo-Json
You'll see this output:

  {
    "Name":  "notepad.exe",
    "LastWriteTime":  "\/Date(1626957326200)\/"
  }
Microsoft didn't fix their weird JSON serialization until quite late. They may have back ported it to the .Net Framework, but they've deleted that documentation. Powershell v6 and v7 include the newer classes that are properly behaved. This is why Json.NET used to be so popular and ubiquitous for C# and ASP applications. It generated JSON like most web applications do, not the way Microsoft's wonky class did. Indeed, I believe it may be what System.Text.Json is based on.
Re:Time to retire the CSV? by cpx86 on Thursday August 19, 2021 @12:02PM (#28235533)
Oh that one - yeah I've always steered clear of DataContractJsonSerializer. Never understood why they did it so weird.

To be fair, RFC 3339 wasn't even published back when this class was implemented (in .NET 3.5) so I guess they just went with whatever worked for their needs. ¯\_(ツ)_/¯

Re:Time to retire the CSV? by da_chicken on Thursday August 19, 2021 @01:32PM (#28236767)
I'd be quicker to believe that it's because 2007 was still in the middle of Steve Ballmer's Microsoft, where embrace-extend-extinguish was their de jure practice.
Re:Time to retire the CSV? by a9h74j on Wednesday August 18, 2021 @11:45PM (#28230121)
I have wondered about a file format where a parser could be specified for [at the start of] each line. You could even have different json parsers with different well-characterized limits and relative speeds. Formats could change over time on a line-by-line basis, without being locked into a full-file IDL or similar.
Re:Time to retire the CSV? by cdcarter on Wednesday August 18, 2021 @05:08PM (#28227180)
JSON Lines is a specified format that answers those questions. https://jsonlines.org/ Seems like it qualifies to the level of authority you're requiring.
Re:Time to retire the CSV? by osigurdson on Wednesday August 18, 2021 @11:49AM (#28222966)
Take an Excel file and change the extension to .zip, then extract the contents. You will see that it is a collection of XML files. Therefore it should be reasonable to conclude that this approach can work for Excel sized datasets.

However it is not particularly readable/diff-able if this is part of your use case.

Re:Time to retire the CSV? by ectopod on Wednesday August 18, 2021 @04:30PM (#28226686)
Excel actually defines a simple XML-based alternative to CSV:

https://en.wikipedia.org/wiki/Microsoft_Excel#XML_Spreadshee...

Re:Time to retire the CSV? by unnouinceput on Wednesday August 18, 2021 @01:52PM (#28224738)
Correction: the new xlsx is a zip file, the old xls format is true binary.
Re:Time to retire the CSV? by dtparr on Wednesday August 18, 2021 @04:57PM (#28227049)
To be fair, xlsx came out with Office 2007, so it's not exactly 'new' anymore. Perhaps at this point it's reasonable for 'excel file' to mean the one that's been the default for 14 years?
Re:Time to retire the CSV? by mavhc on Wednesday August 18, 2021 @05:42PM (#28227558)
So not the one the uk used to track covid infections, sigh.
Re:Time to retire the CSV? by shakna on Wednesday August 18, 2021 @07:21PM (#28228447)
The xlsx document is based on the OpenDocument format, which actually came out in '05, so it's a wee bit older than that.
Re:Time to retire the CSV? by meepmorp on Wednesday August 18, 2021 @08:34PM (#28228991)
Do you mean the OLE-based format, or the really old one?
Re:Time to retire the CSV? by anigbrowl on Wednesday August 18, 2021 @05:52PM (#28227642)
That's useful to know.
Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @03:53PM (#28226284)
>the fact that both of its separators (newlines and commas) can appear as-is inside column values, with a different meaning, if those column-values are quoted, means that there's no way to parallelize CSV processing, because there's no way to read-ahead and "chunk" a CSV purely lexically

Yes, this is a major pain. It can be avoided by using Tab separated value (TSV) files, which don't use escaping. But then you can't store Tabs or carriage returns in your data. Also there is no way to store metadata in TSV.

JSON is far from ideal for storing 2D data tables as it is a tree. This means it is much more verbose than it needs to be. The same is also true for XML.

Re:Time to retire the CSV? by divbzero on Wednesday August 18, 2021 @05:01PM (#28227097)
ASCII has special delimiters 0x1E Record Separator and 0x1F Unit Separator to avoid conflicting with values, but they have never gained widespread adoption.
Re:Time to retire the CSV? by CRConrad on Wednesday September 01, 2021 @10:03AM (#28379953)
> ASCII has special delimiters 0x1E Record Separator and 0x1F Unit Separator

And since ASCII has them, Unicode has them too.

Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @05:22PM (#28227345)
While these have clear advantages over comma and CR for parsing (no more escaping!), they aren't at all convenient for manual editing.
Re:Time to retire the CSV? by mavhc on Wednesday August 18, 2021 @05:41PM (#28227541)
If they were popular they'd be supported in your editor though.
Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @06:03PM (#28227727)
Maybe. It is a bit of a chicken-and-egg problem though. They aren't likely to become popular until editors support them.

Also, the fact that they have been around for years and never taken off implies that they probably never will.

Re:Time to retire the CSV? by sli on Wednesday August 18, 2021 @08:25PM (#28228936)
More generally than editor support, how is the average person expected to type them? I could easily add them to my keyboard, but if "editor support" turned out to mean "Edit > Insert > Record Separator Character" and I was now bound only to editors that support this, absolutely nobody is going to bother. They specifically need to be trivially typable in exactly the way commas and newlines are.

Realistically I don't think anyone (at least on HN) would presume that editor support would be so weirdly obtuse, but it's not exactly well-defined here, either.

I'm mostly just thinking out loud, here, not really critiquing anyone.

Re:Time to retire the CSV? by mavhc on Thursday August 19, 2021 @02:58AM (#28231143)
Commas and Newlines are only trivial if your data contains no commas or newlines.

Who's writing CSV files by hand though?

I'd expect some kind of CSV mode in my text editor where Tab and Newlines are turned into keys to insert those characters

Re:Time to retire the CSV? by kevin_thibedeau on Wednesday August 18, 2021 @08:54PM (#28229120)
> how is the average person expected to type them?

[modifier]-[C,D,E,F]

Re:Time to retire the CSV? by epmos on Thursday August 19, 2021 @06:43AM (#28232278)
Actually, there is already a standard way for someone to type these with the control key. To be specific, they are:

  FS: ^\ GS: ^] RS: ^^ US: ^_
Since these delimiters are not much used, on many terminals ^\ is mapped to send SIGQUIT. Use 'stty quit undef' and you can then type this at the keyboard. This works on Linux and OS X, and likely most other systems. Note that with most keyboards you are also using shift for RS and US. For emacs, prefix with C-q so that it inserts the literal.

Other posters have noted that they have ASCII separators recently, I have as recently as 2018 internally at a FAANG. So they are not completely unknown in the wild.

Re:Time to retire the CSV? by xkgt on Thursday August 19, 2021 @01:28AM (#28230642)
which modifier would that be, Alt/Ctrl or Cmd? Also there is a chance that this combo will not work on some platforms, some may already be in use as a hotkey.
Re:Time to retire the CSV? by nicoburns on Wednesday August 18, 2021 @05:14PM (#28227265)
I worked on a project that used these in a proprietary file format. It was actually quite nice. There was no escaping required because they simply stripped those characters out of the actual content.
Re:Time to retire the CSV? by a1369209993 on Wednesday August 18, 2021 @09:31PM (#28229339)
> but they have never gained widespread adoption.

Yes, because that just kicks the can down the road: how do you represent the one-byte string "\x1E"?

Re:Time to retire the CSV? by BenjiWiebe on Wednesday August 18, 2021 @10:12PM (#28229574)
At least very few humans type that into their spreadsheet cell.
Re:Time to retire the CSV? by Fwirt on Thursday August 19, 2021 @03:14AM (#28231219)
The other advantage not being discussed here is that once you have a csv parser, it can be trivially generalized to use any character as a delimiter, and you can usually find a character that isn't found in the data you're working with unless you're working with binary data. I work on a legacy system where passing delimited files around is usually the integration method of the day, and if you can't delimit with commas (common) then you just delimit with tabs. If you can't delimit with tabs or commas, then delimit with pipes, which are rarely if ever used outside of code. Or use tildes, or grave accents, or...

Doing this avoids quoting, which avoids an entire class of problems. And yes, if you're passing multi-megabyte files around on a regular basis, or transferring giant blobs of text or binary data, or looking for a storage format with metadata then csvs are an absolutely awful choice, but as with any problem you pick the right tool for the job, and csvs are a great tool when you want to easily move some structured alphanumeric data around in a format that's trivial to parse in any language and widely supported.

Re:Time to retire the CSV? by hermitcrab on Thursday August 19, 2021 @03:40AM (#28231366)
>it can be trivially generalized to use any character as a delimiter

But then you have the additional problem of trying to work out what the delimiter is. You can take an educated guess, but this isn't going to be 100% reliable.

Re:Time to retire the CSV? by Fwirt on Thursday August 19, 2021 @06:49PM (#28240328)
This comes back to "picking the right tool for the job". If you're ingesting csvs/tsvs, you're expecting a given format anyway. If you expect the wrong delimiter, the worst thing that happens is you detect that the file has the wrong number of columns and fail out. Even if you're using a more structured format, if you ingest a file containing the wrong dataset, your process will still fail because the correct fields aren't there. No matter what your format is, you can't recover from somebody sending you the wrong file.
Re:Time to retire the CSV? by joquarky on Friday August 27, 2021 @12:16PM (#28329638)
Make it a standard to always put the delimiter as the last character on the first line.
Re:Time to retire the CSV? by gsich on Wednesday August 18, 2021 @12:24PM (#28223514)
If you interpret "CSV" as purely comma seperated values then maybe. But in my bubble "CSV" means textfiles that are separated by some separator. Be it tabs, spaces, commas, or any other ASCII character. Some are more usable then others, if you have commas in your data then use tabs. If you have tabs use Form Feed or Record Separator or vertical tabs ... and so on.

Of course this is not always applicable, since you sometimes don't control the format you get your data.

Re:Time to retire the CSV? by jolmg on Wednesday August 18, 2021 @12:44PM (#28223784)
> But in my bubble "CSV" means textfiles that are separated by some separator. Be it tabs, spaces, commas, or any other ASCII character. Some are more usable then others, if you have commas in your data then use tabs. If you have tabs use Form Feed or Record Separator or vertical tabs ... and so on. Of course this is not always applicable, since you sometimes don't control the format you get your data.

When I see CSV parsers like https://www.papaparse.com/ that even try to support comments and empty lines in the format, I wonder if it'd really be that bad to just raise an error on anything that doesn't fit RFC 4180[1], with explanation on where and how the file is corrupted. Push the issue to the writers of such files.

Then I remember the Robustness Principle[2] and I chill a little.

[1] https://datatracker.ietf.org/doc/html/rfc4180

[2] https://en.wikipedia.org/wiki/Robustness_principle

Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @04:14PM (#28226486)
It seems quite common in some European countries to use semi-colons as the delimiter instead of commas (because they use commas as the decimal separator?), adding a new level of fun to parsing. In Easy Data Transform we count the number of commas, semi-colons, tabs in the file to make an educated guess as the delimiter (which the user can override).
Re:Time to retire the CSV? by unnah on Thursday August 19, 2021 @02:43AM (#28231071)
Semicolon-separated "CSV" is a quirk of Microsoft Excel, which they have never fixed. I figure Microsoft would prefer that people use XLS instead of CSV.
Re:Time to retire the CSV? by worik on Wednesday August 18, 2021 @09:28PM (#28229323)
Pipe '|' here
Re:Time to retire the CSV? by asdff on Wednesday August 18, 2021 @01:17PM (#28224326)
Those other things have different names like TSV
Re:Time to retire the CSV? by jhbadger on Wednesday August 18, 2021 @01:58PM (#28224820)
In theory, yes, to be pedantic, but for example, LibreOffice saves its exported CSVs by default as tab delimited. You actually have to manually specify you want commas to get those.
Re:Time to retire the CSV? by jolmg on Wednesday August 18, 2021 @02:59PM (#28225685)
> LibreOffice saves its exported CSVs by default as tab delimited

Maybe it's actually presenting what you've selected last?

It's giving me comma as the default separator, and it's the first option in the dropdown. Tab is the 3rd option.

>> Those other things have different names like TSV

That depends on the writer. I've gotten what should be named PTVs (pipe-terminated values) as CSVs. I can understand how it happened. If the underlying software outputs PTVs, you don't want to bother converting that because you're working in a legacy language that's a pain to work with (the type where identifiers can't be longer than 4 chars), and you want the user to be able to double-click on it and have it open in a spreadsheet without prior configuration, you just push the issue to the reader of the file, since by tradition readers are already quite tolerant of format differences...

Of course, there'll always be the case where the reader is simply not tolerant enough, like when the escaping syntax differs. There doesn't seem to be a way to get LO Calc to interpret "foo|bar\|baz|" as cells "foo" and "bar|baz", for example.

Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @04:09PM (#28226426)
And then Excel imports them all using heuristics when you select "Type: CSV". So you'll never train anyone on the demand end of these documents that they're called anything besides CSVs.
Re:Time to retire the CSV? by gsich on Wednesday August 18, 2021 @06:04PM (#28227733)
Technically true, but like I said "CSV" is more a term for human readable data, with some delimiter in them. Maybe it's a comma, maybe not. In every case you need someonne to look at it. If you want a machine-machine data protocol you can use XML or JSON if it needs to be somewhat human readable.
Re:Time to retire the CSV? by grumple on Wednesday August 18, 2021 @01:28PM (#28224490)
Commas, quotes, colons, newlines, and hyphens (JSON and YAML separators) can occur in content as well. How is that any different from separators occurring in csvs?

In practice, I used TSVs a lot, as tabs do not usually occur in most data. Alternatively, you could use pipes (|) or control characters as field or row separators.

Re:Time to retire the CSV? by stickfigure on Wednesday August 18, 2021 @01:29PM (#28224494)
JSON/JSONL is not self-describing for many of the most common tabular data use cases. There's no date type or currency type.

If you are going to displace a standard, it has to be significantly better than the old.

Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @01:54PM (#28224770)
CSV does not have date or currency types. Those are an Excel conventional microformat overlaid on top of CSV.

The semantics of CSV — how it decodes, if you don't have an application making additional configured assumptions or using heuristics to detect microformats — is just N columns, one of header names, N of raw text cells. Nothing more, nothing less. No schema defining what a column's type is.

Re:Time to retire the CSV? by stickfigure on Wednesday August 18, 2021 @02:38PM (#28225385)
You misunderstood my point. CSV, for all its faults (and I am intimately aware of them), is ubiquitous. You're not going to replace a widespread standard with something that only offers a tiny incremental improvement. Ubiquitous is a feature, and generally trumps all other features.

If you want something better than CSV to take off, at the very least it needs to solve the common pain points of CSV. JSON doesn't - all it brings to the table is the ability to distinguish number vs text. That's a yawn.

Re:Time to retire the CSV? by breck on Wednesday August 18, 2021 @04:30PM (#28226688)
> If you want something better than CSV to take off...JSON doesn't...

Agreed. I don't ever see something better than CSV taking off (having worked on this problem for better part of a decade) unless you could get to the point where you've got a largely similar notation, but a richer semantic grammar powered by something like Schema.org.

In other words, a strongly typed CSV with a community backed schema. I think GPT-3 and the like are a big wild card here. I can't describe how, but I expect in 20 years we will be using something better for storing data and will look back and saw "CSV used to be the best but then GPT-N _____________".

Re:Time to retire the CSV? by lmm on Thursday August 19, 2021 @12:02AM (#28230198)
> If you want something better than CSV to take off, at the very least it needs to solve the common pain points of CSV. JSON doesn't - all it brings to the table is the ability to distinguish number vs text. That's a yawn.

It brings the ability to parse in parallel - that's a big deal. And while number vs text might not be a huge difference in theory, in practice it eliminates what, 95% of real-world parse problems?

Re:Time to retire the CSV? by stickfigure on Thursday August 19, 2021 @03:10AM (#28231198)
At least in my experience, I don't see a lot of trouble with number vs string in CSV data. You convert the string to a number or you don't. The pain points are usually dates or currencies - the same problem I usually have with JSON, because there's no standard format.

I think you could fix most of the pain of CSV simply by adding a second header row which defines the type of the column, using a common vocabulary of types. TEXT, NUMBER, ISO8861-DATE, etc.

Re:Time to retire the CSV? by lmm on Friday August 20, 2021 @04:17AM (#28243840)
> I don't see a lot of trouble with number vs string in CSV data. You convert the string to a number or you don't.

The trouble is that a lot of existing software (not just Excel) won't properly roundtrip text that looks like numbers and will e.g. strip the leading zero from phone numbers, or worse, change the last digit to make a number that exists in floating point.

> The pain points are usually dates or currencies - the same problem I usually have with JSON, because there's no standard format.

Hmm, I've never had a problem with ISO8861 dates - a string is either a valid date or not, it's very rare for someone to "accidentally" put data in ISO8861 format when it's not actually a date. Dates without timezones can cause problems, but that's more of a semantic issue than a serialization issue. What are the problems that you get?

I can see how currencies could be an issue with the lack of a standardised fixed-precision type. But in my experience they're an order of magnitude less common than issues with phone numbers, postal codes, and the like.

> I think you could fix most of the pain of CSV simply by adding a second header row which defines the type of the column, using a common vocabulary of types. TEXT, NUMBER, ISO8861-DATE, etc.

I'm sure you could. But at that point you're defining a new and incompatible format - you have to make it incompatible, or otherwise people will open these files with a tool that doesn't understand the header format and you're back to square 1 - so you'll pay all the same adoption costs as a completely new format. So it make sense to fix all the issues we can - and a format which can be split and parsed is definitely a major improvement for many use cases.

Re:Time to retire the CSV? by vertere on Thursday August 19, 2021 @05:08AM (#28231790)
I envy your life of pristine CSVs and compatible implementations, where JSON doesn't solve any problems. But CSVs have a broad range of uses, and there are, in fact, plenty of implementations that do not follow RFC 4180, and even if everything did there would still be issues like the header row being optional (without an in-band way of telling). JSON is, in practice, much more well-defined.

On text vs numbers, at least some widely-used software (e.g. R, Excel) will try to guess for you. It should be obvious how this might cause problems. Maybe one should turn auto-conversion off (or not use things that don't let you turn it off) and specify which columns are numbers. Some datasets have a lot of columns, so this can be a PITA, even if you do know which ones should be numbers. But the bigger problem is if you have to deal with other people, or the files that they've touched. There are always going to be people that edit data in excel, don't use the right options when they import, etc.

Re:Time to retire the CSV? by davidinosauro on Friday August 20, 2021 @12:24AM (#28242561)
> At least in my experience, I don't see a lot of trouble with number vs string in CSV data.

I definitely had my fair share of trouble with locale-defined number format. Importing a column where a thousand is spelled "1.000", any integer between 1000 and 999999 would be wrongly parsed as a float between 1 and 999, while for any other number (like "0,1" for one tenth, "1.000.000" for a million, "1.000,56" for a thousand euros and change) the parser would give up and keep the string.

I usually have had more luck importing as text, then doing some string replacement of separators before finally converting to number.

Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @03:11PM (#28225809)
JSON solves tons and tons of pain points around CSV... for implementing anything that reads/imports/normalizes CSV data. Just the fact that CSV has multiple standards around the quote/escape/separator/NULL character-sequences, with the choice not get encoded into the document, means that any format that doesn't have that problem is instantly 100x better in terms of not experiencing a disaster of data-garbling-on-import.
Re:Time to retire the CSV? by Sunspark on Wednesday August 18, 2021 @11:54AM (#28223053)
The formats you describe sound interesting, but in the big corporate/government world the barriers to adoption are high. For example, the software package Cognos which is owned by IBM and connects to database servers. To extract data from it, you have a choice of csv, Excel or pdf. The pdf is only used if you have done a perfect job creating a report in Cognos and don't need to edit/adjust it further in Excel. So really, only 2 output formats.

I realize that this is a specific use case here, but I was on Cognos for years, and then when they started shifting over to Tableau, it wasn't any better.. csv, MS formats, proprietary formats, etc.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @12:23PM (#28223492)
Cognos is a BI tool, and the formats you are talking about are for rendering reports, not data. If you're picking data formats based on being able to load & edit them in to Excel, you're already doomed.
Re:Time to retire the CSV? by tw04 on Wednesday August 18, 2021 @12:42PM (#28223744)
The entire article is about replacing CSVs for exchanging data exported from Excel... so why wouldn't he be picking data formats based on being able to load and edit them in Excel? If you're trying to solve this problem in a way that EXCLUDES Excel, you're already doomed. The business world will laugh at you and continue on their merry CSV way.

>The biggest and most thorny problem to solve is the people problem: how do you convince people to stop creating new CSVs when they’ve never done things any other way? Fortunately - for this problem, anyway - most of the world’s business data is born in one of a handful of programs that are owned by an increasingly small number of companies. If Microsoft and Salesforce were somehow convinced to move away from CSV support in Excel and Tableau, a large portion of business users would move to a successor format as a matter of course. Of course, it’s debatable whether that kind of a change is in the best interest of those companies, but I’m cautiously optimistic.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @12:50PM (#28223868)
> The entire article is about replacing CSVs for exchanging data exported from Excel...

No, it's not. It's about replacing CSVs for exchanging data. It mentions that CSVs often are the product of someone exporting data from a spreadsheet or doing a table dump, and how just doing that tends to create a ton of problems, but Excel is an example, not the subject matter of the article.

> The business world will laugh at you and continue on their merry CSV way.

The business world pays me a lot of money to teach them not to use CSVs.

Re:Time to retire the CSV? by masklinn on Wednesday August 18, 2021 @01:20PM (#28224366)
> The business world pays me a lot of money to teach them not to use CSVs.

Could you teach them better and faster? I don't think they're getting it. You have my blessing to use violence.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @01:42PM (#28224636)
> Could you teach them better and faster? I don't think they're getting it. You have my blessing to use violence.

I'm trying man. I'm trying.

Re:Time to retire the CSV? by barbarbar on Wednesday August 18, 2021 @11:26PM (#28230024)
This is the right suggestion.
Re:Time to retire the CSV? by wombatpm on Wednesday August 18, 2021 @02:06PM (#28224933)
Of course there is a old solution in the ANSI character set. File, Record, Group and Unit separator characters
Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @04:09PM (#28226429)
Yes. You could get a long way with a text format in which:

-the first line is always a header

-fields are separated by Unit separator characters

-records are separated by Record separator characters

-encoding is UTF8

If you wanted to get fancy you could also have:

-comment lines

-column metadata (e.g. column 0 is an ISO date, column 2 is text, column 3 is an integer)

Both the above could start with a Unicode character unlikely to be used for anything else.

I think that would avoid 99% of the pain of CSV files. The downside is that the use of things like the Unit separator mean that it wouldn't be easy to create/edit manually.

I don't suppose it will ever happen though.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @05:52PM (#28227640)
> it wouldn't be easy to create/edit manually

I mean, you'd have to be using a pretty terrible tool for it not being able to handle that, and I suspect if such an approach were to become prevalent, that tool would either fix the glitch or become largely unused.

Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @06:00PM (#28227704)
Are there any editors that let you insert a Unit separator character as easily as a comma?
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @06:05PM (#28227744)
All of the programmable ones? ;-)
Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @06:15PM (#28227831)
So that's a no then. ;0P
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @10:12PM (#28229583)
? Quite the contrary. It's more, "all the ones that any craftsman should be using".
Re:Time to retire the CSV? by lanstin on Thursday August 19, 2021 @12:34AM (#28230351)
A lot of excels and csvs are made by people other than programming crafters.
Re:Time to retire the CSV? by scbrg on Thursday August 19, 2021 @04:33AM (#28231632)
As with pretty much everything else computing, the world suffers because Microsoft has been dumping terrible tools on it for decades, and people just take their garbage as the way things have to be.
Re:Time to retire the CSV? by cbsmith on Thursday August 19, 2021 @07:09AM (#28232430)
Excel has its advantages, but it is funny the tools people choose to work with. The number of times Access would make more sense...
Re:Time to retire the CSV? by atatatat on Thursday August 19, 2021 @10:28AM (#28234251)
Didn't they sunset Access in lieu of Power BI Apps or whatever the hell they're calling their shot at no code these days?
Re:Time to retire the CSV? by cbsmith on Thursday August 19, 2021 @12:44PM (#28236089)
Re:Time to retire the CSV? by cbsmith on Thursday August 19, 2021 @07:08AM (#28232422)
Yes indeed. It often means they do extra work because they're using the wrong tools.

But you gotta admit that excel is a pretty terrible tool to hand edit a CSV with... ;-)

Re:Time to retire the CSV? by barbarbar on Wednesday August 18, 2021 @11:19PM (#28229973)
But it sounds like a very very good approach.
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @03:14PM (#28225850)
Yup. I mean, if you're going to go with a text encoding, you might want to, you know, use the features of the text encoding that were put there explicitly for said purpose...

...or you could invent abominations like CSV, TSV, etc. ;-)

Re:Time to retire the CSV? by wombatpm on Wednesday August 18, 2021 @02:03PM (#28224901)
TSV solve a lot of the pain
Re:Time to retire the CSV? by hermitcrab on Wednesday August 18, 2021 @04:10PM (#28226441)
As long as you don't need to store tabs or carriage returns in your data. ;0)
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @03:13PM (#28225838)
...or, you know, you could use the ASCII characters specifically defined for separating records and units. ;-)
Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @04:07PM (#28226409)
If only I could type them on my keyboard. (I think this is a big part of why CSV is the way it is — people want to be able to hand-edit it, or at least hand-produce small test datasets to test the systems on the other end.)
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @04:16PM (#28226508)
The funny thing is you can type any character on a keyboard. It's the same weird disconnect about "text file formats are human-readable". Either way you need a tool that can render & read the format in question. It does't much matter what format you actually store the data in, because you don't read & write the bites directly.
Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @12:11PM (#28223316)
> There's also Avro, which fails your point #1 (it's a binary format) but that binary format is a lossless alternate encoding of what's canonically a JSON document, and there are both simple CLI tools / and small, free, high-quality libraries that can map back and forth between the "raw" JSON document and the Avro-encoded file. At any time, you can decode the Avro-encoded file to text, to examine/modify it in a text editor.

Avro is not a lossless alternate encoding of what's canonically a JSON document. Yes Avro supports a JSON encoding, but it's not canonical.

In general though, you're point about Avro being able to be represented as text is valid, and applies to practically any binary formThere's also Avro, which fails your point #1 (it's a binary format) but that binary format is a lossless alternate encoding of what's canonically a JSON document, and there are both simple CLI tools / and small, free, high-quality libraries that can map back and forth between the "raw" JSON document and the Avro-encoded file. At any time, you can decode the Avro-encoded file to text, to examine/modify it in a text editor.at, which is why the whole "but it needs to be a text format" argument is garbage.

> The data-warehouse ecosystem already standardized on Avro as its data interchange format. And spreadsheets are just tiny data warehouses. So why not? ;)

I wish that the data-warehouse ecosystem standardized on anything. ;-)

That said, there are plenty of good reasons why a data-warehouse standard would not be advisable for spreadsheets.

Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @01:59PM (#28224841)
> Yes Avro supports a JSON encoding, but it's not canonical.

To be clear, I'm not talking about using an Avro library to encode data to JSON. I'm saying that when you decode an Avro document, the result that comes out — presuming you don't tell the Avro decoder anything special about custom types your runtime supports and how it should map them — is a JSON document.

Where, by "JSON document" here, I don't mean "a JSON-encoded text string", but rather an in-memory ADT that has the exact set of types that exist in JSON, no more and no less. The sum-type of (JSONArray | JSONObject | String | Integer | Float | true | false | null). The "top" expression type recognized by a JSON parser. Some might call such a document a "JSON DOM." But usually it's a "JSON document", same as how the ADT you get by parsing XML is usually referred to as an "XML document."

Or, to put that another way, Avro is a way to encode JSON-typed data, just as "JSON text", or https://bsonspec.org/, is a way to encode JSON-typed data. They're all alternative encodings that have equivalent lossless encoding power over the same supported inputs.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @02:29PM (#28225272)
> I'm saying that when you decode an Avro document, the result that comes out (presuming you don't tell the Avro decoder anything special about custom types your runtime supports and how it should map them) is a JSON document.

Semantic point: it's not a "document".

There are tools which will decode Avro and output the data in JSON (typically using the JSON encoding of Avro: https://avro.apache.org/docs/current/spec.html#json_encoding), but the ADT that is created is by no means a JSON document. The ADT that is created has more complex semantics than JSON; JSON is not the canonical representation.

> By which I don't mean JSON-encoded text, but rather an in-memory ADT that has the exact set of types that exist in JSON, no more and no less.

Except Avro has data types that are not the exact set of types that exist in JSON. The first clue on this might be that the Avro spec includes mappings that list how primitive Avro types are mapped to JSON types.

> Or, to put that another way, Avro is a way to encode JSON-typed data, just as "JSON text", or https://bsonspec.org/, is a way to encode JSON-typed data

BSON, by design, was meant to be a more efficient way to encode JSON data, so yes, it is a way to encode JSON-typed data. Avro, however, was not defined as a way to encode JSON data. It was defined as a way to encode data (with a degree of specialization for the case of Hadoop sequence files, where you are generally storing a large number of small records in one file).

A simple counter example: Avro has a "float" type, which is a 32-bit IEEE 754 floating point number. Neither JSON nor BSON have that type.

Technically, JSON doesn't really have types, it has values, but even if you pretend that JavaScript's types are JSON's types, there's nothing "canonical" about JavaScript's types for Avro.

Yes, you can represent JSON data in Avro, and Avro in JSON, much as you can represent data in two different serialization formats. Avro's data model is very much defined independently of JSON's data model (as you'd expect).

Re:Time to retire the CSV? by derefr on Wednesday August 18, 2021 @03:42PM (#28226154)
> The first clue on this might be that the Avro spec includes mappings that list how primitive Avro types are mapped to JSON types.

My understanding was always:

1. that the "primitive Avro types" are Avro's wire types, which are separate from its representable domain types. (Sort of like how RLE-ified data has wire types of "literal string" and "repeat literal N times".)

2. that any data that would not be valid as input to a JSON encoder, is not valid as input to an Avro encoder, because its wire types are defined in terms of their a mapping from a set of domain types that are exactly the set of domain types accepted by JSON encoders (whether they're explicitly noted as being those or not.)

Or, to put that another way: an Avro schema is — besides a validation step that constrains your data into a slightly-more-normalized/cleaned format — mostly a big fat hint for how to most-efficiently pack an (IMHO strictly JSONly-typed) value into a binary encoding. Differences between "long" and "int" on the wire aren't meant to decode to different domain types (at least, by default); they're just meant to restrict the data's allowed values (like a SQL DOMAIN constraint) in ways that allow it to be more predictable, and so to be wire-encoded more optimally.

Let me lay out some evidence for that assertion:

• Avro supports specifying e.g. "bytes" vs. {"array": "byte"} — there's literally no domain-type difference in those! But one is a wire-encoding optimization over the other.

• Avro has a "default" property, and this property—as part of the JSON-typed schema—can only take on JSON-typed values. Do you think this is an implementation constraint, or a design choice?

• Avro's enum type's "symbols" array? Once again, defined by (and therefore limited to) JSON string values.

• Avro doesn't implement an arbitrary-precision integer type, even though its wire-encoding for integers would support one just fine. Why? Seemingly only because JSON doesn't have an arbitrary-precision integer type (because JavaScript doesn't have a native BigNum type); nor does JavaScript/JSON have any obvious type to O(1)-efficiently deserialize a BigNum out into. (Deserializing BigNums to strings wouldn't be O(1).) Every other language offers a clean 1:1 mapping for bignums, but JavaScript doesn't, so JSON didn't, so Avro doesn't.

• And why do you think Avro schemas are stored as embedded explicitly-defined-to-be-JSON documents within the root-level record / .avsc file, anyway? This means that you are required to have a JSON decoder around (either at decode time, or at decoder codegen time) to decode Avro documents. Why would this be, if not because the Avro implementation is (ot at least originally was) expected to decode the Avro document's wire types into the JSON library's already-defined ADTs, relying on e.g. having those "default"-parameter values already loaded in in JSON-value format from the schema's decode-output, ready to be dropped seamlessly into the resulting Avro decode-output?

And the biggest knock-down argument I'm aware of:

• Avro "string" doesn't support "\u0000". Why not? Because as you've said, Avro has a "JSON encoding", which specifies one-to-one mapping for strings; and JSON doesn't support "\u0000" in strings. (Just ask Postgres's jsonb type about that.) Since an Avro string containing "\u0000" wouldn't round-trip losslessly between the JSON and binary wire-encodings, it's not allowed in strings in the binary encoding.

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @04:47PM (#28226901)
Since it is a serialization format, Avro's types are its wire types. However, the primitive types are just a subset of the types that Avro supports.

Based on these comments, my best guess is you got the idea that Avro was for encoding JSON because the schema declaration is encoded in JSON, but that's not nearly the same as the data model. There are some terrible implementations of Avro libraries out there that use JSON as some kind of middleware, but that's not how Avro actually works.

If there's a type model it is derived from at all, it's the Java type model.

"byte" is not a valid type in Avro. There is only "bytes", and the domain model reflects this. You can't work with individual "byte" of a "bytes" object.

Default values are encoded in the schema, and so that does limit what kind of default values you can have, but again this is a limitation derived from the schema being defined in JSON, and how the schema language was defined in general. So your defaults have to be represented as JSON literals, but they don't even necessarily share the type of the JSON literal (e.g. a field defined as: '{"name": "foo", "type": "long", "default":1}' does not have the same default value as '{"name": "bar", "type": "int", "default":1}", because "foo" has a default value that is a long while "bar" has one that is an "int"). Note that "default values" are a property of the type, and only apply to elements inside complex data types. JSON has no such equivalent concept.

Avro's type model does have an arbitrary precision type that doesn't correlate to anything in JSON: the "decimal" logical type.

You aren't required to use a JSON decoder to decode Avro documents, nor are you required to use a .avsc file. The Avro schema file is just the standard way to represent a schema. If you have the schema, you don't need the file. JSON schema files are one of the poorer choices in the Avro design, but you'll notice that the schema is defined the way it is specifically so that it can cover a type model well outside of JSON. You'll also notice the names of types in Avro don't directly correlate to names of types in JSON.

* The \u0000 thing is a bug in avro tools, but there is nothing about the spec that prohibits having \u0000 in your strings.

I feel like in general this is like a retcon exercise, where you've reached a conclusion and are drawing evidence to prove it, while ignoring the information that contradicts. I spoke with Cutting a fair bit when he came up with Avro, and I can assure you, while the schema language does very intentionally use JSON, Avro is not a representation for JSON types.

Re:Time to retire the CSV? by amyjess on Wednesday August 18, 2021 @06:37PM (#28228028)
As someone who's used Avro [0], it's a pain because Avro records must be ordered, but JSON by definition is unordered. Avro's "JSON" format is more of a JSON-like format. At one point, when I was writing a script that would ingest an Avro record and then output a new one, I had to fiddle with things to make Python use an OrderedDict [1] so the new record would be output in the right order.

[0] though the last time I touched it was in 2014, so things might've changed since

[1] as per [0], this was before Python dicts were ordered by default

Re:Time to retire the CSV? by cbsmith on Wednesday August 18, 2021 @10:20PM (#28229624)
I'm not sure what you mean by Avro records "must" be ordered. If you mean that the serialization format specifies the ordering of the fields, then yes, that is true, but that's an advantage in terms of compactness and processing efficiency (https://avro.apache.org/docs/current/spec.html#order). If you don't like it though, there are other formats like protobuf and thrift that have no such requirement, at the cost of ~3 bits per field, which can be a comparatively efficient trade off.
Re:Time to retire the CSV? by amyjess on Thursday August 19, 2021 @02:52PM (#28237755)
The problem is that fields aren't ordered in the JSON spec, so fields being ordered in Avro's dialect of JSON automatically makes it non-standard JSON which makes it difficult to use standard tooling with Avro JSON.
Re:Time to retire the CSV? by cbsmith on Friday August 20, 2021 @10:59AM (#28246802)
OIC. Yeah, in general the JSON representation is really just for cases where some tool can't handle the binary. Think of it as an escape hatch more than a core feature.

If you're using Avro as a way to do JSON, that's definitely a bad choice. That's why I found the notion of Avro as a way to work with JSON documents as really... odd. (https://news.ycombinator.com/item?id=28222491) It's a decent way to manage data transfers (and I continue to argue a much better one that CSV or JSON), but as a "lossless alternate encoding of what's canonically a JSON document", it's a bad fit.

Re:Time to retire the CSV? by glogla on Wednesday August 18, 2021 @01:14PM (#28224279)
Avro and Parquet and Arrow are almost loseless - they can't handle timestamp with timezone which really sucks for processing world-wide data.

I'm still looking for somwthing that can do it.

(Of course, Spark doesn't support timestampz which is probably why the formats don't.)

Re:Time to retire the CSV? by nonameiguess on Wednesday August 18, 2021 @12:06PM (#28223232)
It's not possible to read ahead and chunk with 100% assurance it will always work, but libraries like pandas and R's data.table do a reasonable job of reading in the first X rows, doing some usually correct type inference on the columns, and then read ahead and chunking the rest of the rows.

For what it's worth, I totally agree something like compressed json lines is a better data exchange format, but part of why csv remains as universal and supported as it is is that so much existing data storage applications export to either csv or excel and that's about it. So any ETL system that can't strictly control the source of its input data has no choice but to support csv.

Re:Time to retire the CSV? by breck on Wednesday August 18, 2021 @04:24PM (#28226615)
> means that there's no way to parallelize CSV processing, because there's no way to read-ahead and "chunk" a CSV purely lexically.

There's a subset of CSV that forbids escapes that is super fast to parse. All fast CSV parsers I'm aware of take advantage of this subset. I try to never ever publish a CSV that has quotes, and always aim for a more restrictive grammar that is cleaner, better thought out data.

Re:Time to retire the CSV? by kaiju0 on Wednesday August 18, 2021 @12:05PM (#28223217)
Most data warehouses I have worked with use character delimited formats.

*shudder

Re:Time to retire the CSV? by veltas on Wednesday August 18, 2021 @04:57PM (#28227046)
>CSV is actually horrible at parse-time vs. other data formats

I find this really hard to believe given it's a simple enough syntax. And parsing is usually not the limiting factor, usually fast enough to not be noticed alongside interpreting or loading the source data. Every (much more sophisticated) compiler I can think of uses a linear parser based on this assumption.

Re:Time to retire the CSV? by mortehu on Wednesday August 18, 2021 @05:07PM (#28227171)
Just extracting string views can be fast, but converting numbers to and from text is very slow.
Re:Time to retire the CSV? by veltas on Thursday August 19, 2021 @08:10AM (#28232783)
But significant compared to time to load the source in the first place? Or any processing that will come after?
Re:Time to retire the CSV? by worik on Wednesday August 18, 2021 @09:29PM (#28229332)
It is a text format. So you will always have to do that conversion.

Binary formats have their own pain points - more of them actually