News for hackers. Stuff that matters.
Re:A love letter to the CSV format by koolba on Wednesday March 26, 2025 @02:14PM (#43485101)
JSON serialized without extra white space with one line per record is superior to CSV.

If you want CSV-ish, enforce an array of strings for each record. Or go further with actual objects and non-string types.

You can even jump to an arbitrary point and then seek till you see an actual new line as it’s always a record boundary.

It’s not that CSV is an invalid format. It’s that libraries and tools to parse CSV tend to suck. Whereas JSON is the lingua franca of data.

Re:A love letter to the CSV format by derriz on Wednesday March 26, 2025 @04:14PM (#43486719)
> It’s that libraries and tools to parse CSV tend to suck. Whereas JSON is the lingua franca of data.

This isn't the case. An incredible amount of effort and ingenuity has gone into CSV parsing because of its ubiquity. Despite the lack of any sort of specification, it's easily the most widely supported data format in existence in terms of tools and language support.

Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @04:41PM (#43487069)
Can you point me to a language with any significant number of users that does NOT have a JSON library?

I went looking at some of the more niche languages like Prolog, COBOL, RPG, APL, Eiffel, Maple, MATLAB, tcl, and a few others. All of these and more had JSON libraries (most had one baked into the standard library).

The exceptions I found (though I didn't look too far) were: Bash (use jq with it), J (an APL variant), Scratch (not exposed to users, but scratch code itself is encoded in JSON), and Forth (I could find implementations, but it's very hard to pin down forth dialects).

Re:A love letter to the CSV format by derriz on Wednesday March 26, 2025 @04:58PM (#43487234)
I made no claim about JSON libraries. I contested the claim that "CSV libraries and tools suck". They do not.
Re:A love letter to the CSV format by FridgeSeal on Wednesday March 26, 2025 @05:46PM (#43487754)
CSV tooling has had to invest enormous amounts of effort to make a fragile, under-specified format half-useful. I would call it ubiquitous, I would call the tooling that we’ve built around it “impressive” but I would by no means call any of it “good”.

I do not miss dealing with csv files in the slightest.

Re:A love letter to the CSV format by freehorse on Wednesday March 26, 2025 @07:48PM (#43488862)
> CSV tooling has had [...] to make a fragile, under-specified format half-useful

You get this backwards. Tabular structured data to store are ubiquitous. Text as a file format is also ubiquitous because it is accessible. The only actual decisions are about whether to encode your variables as rows or columns, what is the delimiter, and other rules such as escaping etc. Vars as columns makes sense because it makes appending easier. There is a bunch of stuff that can be used for delimeters, commas being the most common, none is perfect. But from this point onwards, decisions do not really matter, and "CSV" basically covers everything from now on. "CSV" is basically what comes naturally when you have tabular datasets and want to store them in text. CSV tooling is developed because there is a need for this way of formatting data. Whether CSV is "good" or "ugly" or whatever is irrelevant, handling data is complicated as much as the world itself is. The alternatives are either not structuring/storing the data in a tabular manner, or non-text (eg binary) formats. These alternative exist and are useful in their own right, but don't solve the same problems.

Re:A love letter to the CSV format by ddulaney on Wednesday March 26, 2025 @10:40PM (#43489876)
I think the issue is that CSV parsing is really easy to screw up. You mentioned delimiter choice and escaping, and I’d add header presence/absence to that list.

There are at least 3 knobs to turn every time you want to parse a CSV file. There’s reasonably good tooling around this (for example, Python’s CSV module has 8 parser parameters that let you select stuff), but the fact that you have to worry about these details is itself a problem.

You said “handling data is complicated as much as the world itself is”, and I 100% agree. But the really hard part is understanding what the data means, what it describes. Every second spent on figuring out which CSV parsing option I have to change could be better spent actually thinking about the data.

Re:A love letter to the CSV format by ozim on Thursday March 27, 2025 @02:39AM (#43490944)
I am kind of amazed how people nag about having to parse practically a random file.

Having header or not should be specified up front and one should not parse some unknown file because that will always end up with failure.

If you have your own serialization and your own parsing working yeah this will simply work.

But then not pushing back to the user some errors and trying to deal with everything is going to be frustrating because amount of edge cases is almost infinite.

Handling random data is hard, saying it is a CSV and trying to support everything that comes with it is hard.

Re:A love letter to the CSV format by dylan604 on Wednesday March 26, 2025 @05:59PM (#43487898)
Microsoft Windows has had to invest enormous amounts...

Apple macOS has had to invest enormous amounts...

Pick your distro of Linux has had to invest enormous amounts...

None of them a perfect and any number of valid complaints can be said about any of them. None of the complaints make any of the things useless. Everyone has workarounds.

Hell, JSON has had to invest enormous amounts of effort...

Re:A love letter to the CSV format by FridgeSeal on Wednesday March 26, 2025 @07:47PM (#43488855)
I guess the point is that I can take a generic json parser and point it at just about any JSON I get my hands on, and have close to no issues parsing it.

Want to do the same with csv? Good luck. Delimiter? Configurable. Encoding? Configurable. Misplaced comma? No parse in JSON, in csv: might still parse, but is now semantically incorrect and you possibly won’t know until it’s too late, depending on your parser. The list goes on.

Re:A love letter to the CSV format by pbrumm on Wednesday March 26, 2025 @10:42PM (#43489890)
Here is a quick test

The table of contents points to a single Json object that is 20ish gb compressed

https://www.anthem.com/machine-readable-file/search/

All stock libs will fail

Re:A love letter to the CSV format by jstanley on Wednesday March 26, 2025 @05:37PM (#43487642)
You claimed that CSV is "easily the most widely supported data format in existence in terms of tools and language support", which is a claim that CSV is better supported than JSON, which is a claim that JSON support is lacking.
Re:A love letter to the CSV format by shawabawa3 on Wednesday March 26, 2025 @05:48PM (#43487779)
Can you import .jsonl files into Google sheets or excel natively?
Re:A love letter to the CSV format by freehorse on Wednesday March 26, 2025 @06:06PM (#43487970)
Importing csvs in excel can be a huge pain due to how excel handles localisation. It can basically alter your data if you are not mindful about that, and I have seen it happening too many times.
Re:A love letter to the CSV format by xnx on Wednesday March 26, 2025 @07:34PM (#43488761)
Excel dropping leading zeros (as in ZIP codes) was a crazy design decision that has certainly cost many lifetimes of person-hours.
Re:A love letter to the CSV format by disgruntledphd2 on Thursday March 27, 2025 @03:24AM (#43491177)
And forcing 16+ digits to be floats, destroying information.
Re:A love letter to the CSV format by freehorse on Thursday March 27, 2025 @12:59PM (#43495553)
Yeah have had similar struggles with social security numbers.
Re:A love letter to the CSV format by codetrotter on Wednesday March 26, 2025 @07:01PM (#43488467)
For example:

Scientists rename genes because Microsoft Excel reads them as dates (2020)

https://www.reddit.com/r/programming/comments/i57czq/scienti...

Re:A love letter to the CSV format by TRiG_Ireland on Thursday March 27, 2025 @06:46PM (#43499102)
I was so glad of that story. It gave me something to point to to get my boss off my back.
Re:A love letter to the CSV format by phkahler on Wednesday March 26, 2025 @07:28PM (#43488708)
But it handles it better than Json.
Re:A love letter to the CSV format by freehorse on Wednesday March 26, 2025 @07:51PM (#43488888)
Depends on what you mean by "better". I would rather software not handle a piece of data at all, than handle it erroneously and changing the data without me realising and thus causing all sorts of issues after.
Re:A love letter to the CSV format by d0mine on Thursday March 27, 2025 @12:32AM (#43490411)
In practice, web browsers accept the tag soup that is sometimes called html and strict xml-based formats failed.
Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @04:44AM (#43491519)
The browser are not a database (unlike excel). Modifying data before showing it is reversible, modifying it before storing it is not.
Re:A love letter to the CSV format by niccl on Wednesday March 26, 2025 @07:28PM (#43488710)
Excel.

Before you dismiss it as 'not a language, people have argued that it is. And you can definitely program stuff in it, and so that surely makes it a language

Re:A love letter to the CSV format by squeaky-clean on Wednesday March 26, 2025 @08:17PM (#43489047)
Excel can import and parse JSON, it's under the "Get Data" header. It doesn't have a direct GUI way to export to JSON, but it takes just a few lines in Office Scripts. You can even use embedded TypeScript to call JSON.stringify.
Re:A love letter to the CSV format by otikik on Wednesday March 26, 2025 @04:49PM (#43487156)
Meanwhile, Excel exports to CSV as “semicolon separated values” depending on your OS locale
Re:A love letter to the CSV format by matthewmacleod on Wednesday March 26, 2025 @04:56PM (#43487213)
Albeit for fairly justifiable reasons
Re:A love letter to the CSV format by notpushkin on Wednesday March 26, 2025 @05:00PM (#43487256)
Justifiable how?
Re:A love letter to the CSV format by matthewmacleod on Wednesday March 26, 2025 @07:50PM (#43488883)
Well, Excel has a lot of common use-cases around processing numeric (and particularly financial) data. Since some locales use commas as decimal separators, using a character that's frequently present as a piece of data as a delimiter is a bit silly; it would be hard to think of a _worse_ character to use.

So, that means that Excel in those locales uses semicolons as separators rather than the more-frequently-used-in-data commas. Probably not the decision I'd make in retrospect, but not completely stupid.

Re:A love letter to the CSV format by LoganDark on Wednesday March 26, 2025 @05:03PM (#43487286)
Decimal separators being commas in some locales?
Re:A love letter to the CSV format by otikik on Wednesday March 26, 2025 @05:29PM (#43487548)
They could have just ignored the locale altogether though. Put dots on the numbers when using csv, and assume it has dots when importing
Re:A love letter to the CSV format by notpushkin on Thursday March 27, 2025 @02:09AM (#43490786)
This exactly. Numbers in XLS(X) are (hopefully) not locale-specific – why should they be in CSV?
Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @04:47AM (#43491536)
CSV -> text/csv

Microsoft Excel -> application/vnd.ms-excel

CSV is a text format, xls[x], json, and (mostly) xml are not.

Re:A love letter to the CSV format by ideamotor on Wednesday March 26, 2025 @05:23PM (#43487463)
Commas are commonly used in text, too.
Re:A love letter to the CSV format by susam on Wednesday March 26, 2025 @07:14PM (#43488583)
Clearly they should have gone with BEL as the delimiter.

  printf "alice\007london\007uk\nbob\007paris\007france\n" > data.bsv
I'm hoping no reasonable person would ever use BEL as punctuation or decimal separator.
Re:A love letter to the CSV format by kmoser on Wednesday March 26, 2025 @11:12PM (#43490039)
On the off chance you're not being facetious, why not ASCII 0 as a delimiter? (This is a rhetorical question.)
Re:A love letter to the CSV format by defrost on Wednesday March 26, 2025 @11:17PM (#43490075)
There are some decent arguments for BEL over NUL, however given you posed that as a rhetorical question I feel I can say little other than

ding! ding! ding! winner winner, chicken dinner!

Although BEL would drive me up the wall if I broke out any of my old TTY hardware.

Re:A love letter to the CSV format by mastax on Thursday March 27, 2025 @01:26AM (#43490607)
ASCII has characters more or less designed for this

0x1C - File Separator

0x1D - Group Separator

0x1E - Record Separator

0x1F - Unit Separator

So I guess 1F would be the "comma" and 1E would be the "newline."

Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @04:54AM (#43491573)
https://stackoverflow.com/questions/8695118/what-are-the-fil...

I am pretty sure you shifted the meaning, the decimal separator is part of the atomic data it does not need a control character.

You would use 1F instead of the comma/semicolon/tab and 1E to split lines (record means line just like in SQL).

You could then use 1D to store multiple CSV tables in a single file.

Re:A love letter to the CSV format by pasc1878 on Thursday March 27, 2025 @07:20AM (#43492419)
Yes but then the text is not human readable or editable in a plain text editor.

This would confuse most users of csvs they are not programmers they at most use text editors and Excel.

Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @12:18PM (#43495155)
I am not proposing to do this, but if you were to use ascii separators you would do it this way
Re:A love letter to the CSV format by dessimus on Thursday March 27, 2025 @06:25AM (#43492052)
If one was going to use a non-printable character as a delimiter, why wouldn't they use the literal record separator "\030"?
Re:A love letter to the CSV format by susam on Thursday March 27, 2025 @07:50PM (#43499637)
Every time you cat a BSV file, your terminal beeps like it's throwing a tantrum. A record separator (RS) based file would be missing this feature! In other words, my previous comment was just a joke! :)

By the way, RS is decimal 30 (not octal '\030'). In octal, RS is '\036'. For example:

  $ printf '\036' | xxd -p
  1e
  $ printf '\x1e' | xxd -p
  1e
See also https://en.cppreference.com/w/cpp/language/ascii for confirmation.
Re:A love letter to the CSV format by kevindamm on Wednesday March 26, 2025 @10:09PM (#43489734)
...and excel macros
Re:A love letter to the CSV format by LoganDark on Thursday March 27, 2025 @02:46AM (#43490984)
Sure, let's put quotation marks around all number values.

Oh wait.

lol

Re:A love letter to the CSV format by kentm on Wednesday March 26, 2025 @04:54PM (#43487199)
I’ve found that the number of parsers that don’t handle multiline records is pretty high though.
Re:A love letter to the CSV format by consteval on Wednesday March 26, 2025 @07:24PM (#43488679)
It's widely, but inconsistently, supported. The behavior of importers varies a lot, which is generally not the case for JSON.
Re:A love letter to the CSV format by autoexec on Wednesday March 26, 2025 @08:18PM (#43489051)
> it's easily the most widely supported data format in existence in terms of tools and language support.

Even better, the majority of the time I write/read CSV these days I don't need to use a library or tools at all. It'd be overkill. CSV libraries are best saved for when you're dealing with random CSV files (especially from multiple sources) since the library will handle the minor differences/issues that can pop up in the wild.

Re:A love letter to the CSV format by nukem222 on Wednesday March 26, 2025 @09:02PM (#43489347)
> An incredible amount of effort and ingenuity has gone into CSV parsing because of its ubiquity.

Yea and it's still a partially-parseable shit show with guessed values. But we can and could have and should have done better by simply defining a format to use.

Re:A love letter to the CSV format by recursive on Thursday March 27, 2025 @03:46PM (#43497366)
> Despite the lack of any sort of specification

People keep saying this but RFC 4180 exists.

Re:A love letter to the CSV format by benwilber0 on Wednesday March 26, 2025 @03:06PM (#43485730)
JSON is a textual encoding no different than CSV.

It's just that people tend to use specialized tools for encoding and decoding it instead of like ",".join(row) and row.split(",")

I have seen people try to build up JSON strings like that too, and then you have all the same problems.

So there is no problem with CSV except that maybe it's too deceptively simple. We also see people trying to build things like URLs and query strings without using a proper library.

Re:A love letter to the CSV format by int_19h on Wednesday March 26, 2025 @03:18PM (#43485901)
The problem with CSV is that there's no clear standard, so even if you do reach for a library to parse it, that doesn't ensure compatibility.
Re:A love letter to the CSV format by rcbdev on Wednesday March 26, 2025 @03:42PM (#43486265)
Same for JSON though. What Python considers a valid JSON might not be that if you ask a Java library.
Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @04:05PM (#43486594)
JSON has a clearly-defined standards: ISO/IEC 21778:2017, IETF RFC 7159, and ECMA-404. Additionally, Crockford has had a spec available on json.org since it's creation in 2001.

Do you have any examples of Python, Java, or any of the other Tiobe top 40 languages breaking the JSON spec in their standard library?

In contrast, for the few of those that have CSV libraries, how many of those libraries will simply fail to parse a large number of the .csv variations out there?

Re:A love letter to the CSV format by whizzter on Wednesday March 26, 2025 @04:16PM (#43486756)
Not to mention that stuff like Excel loves to export CSV files in "locale specific ways".

Sometimes commas to delimiter, sometimes semicolons, floating point values might have dots or commas to separate fraction digits.

Not to mention text encodings, Ascii, western european character sets, or maybe utf-8 or whatever...

It's a bloody mess.

Re:A love letter to the CSV format by ohgr on Wednesday March 26, 2025 @07:33PM (#43488754)
That’s why we just email the sheets around like it’s 1999 :)
Re:A love letter to the CSV format by dwattttt on Wednesday March 26, 2025 @04:30PM (#43486935)
You need more than a standard; that standard has to be complete and unambiguous. What you're looking for is https://github.com/nst/JSONTestSuite

EDIT: The readme's results are from 2016, but there's more recent results (last updated 5 years ago). Of the 54 parsers /versions tested, 7 gave always the expected result per the spec (disregarding cases where the spec does not define a result).

Re:A love letter to the CSV format by noitpmeder on Wednesday March 26, 2025 @04:58PM (#43487233)
It falls down under very large integers -- think large valid uint64_t values.
Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @07:15PM (#43488592)
JSON doesn't fail for very large values because they are sent over the wire as strings. Only parsers may fail if they or their backing language doesn't account for BigInts or floats larger than f64, but these problems exist when parsing any string to a number.
Re:A love letter to the CSV format by girvo on Wednesday March 26, 2025 @07:29PM (#43488717)
And indeed applies to CSV as well: it's just strings at the end of the day, its up to the parser to make sense of it into the data types one wants. There is nothing inherently stopping you from parsing a JSON string into a uint64: I've done so plenty!
Re:A love letter to the CSV format by zeroimpl on Wednesday March 26, 2025 @07:49PM (#43488873)
Example? I know there's some ambiguity over whether literals like false are valid JSON, but I can't think of anything else.
Re:A love letter to the CSV format by tubthumper8 on Wednesday March 26, 2025 @09:41PM (#43489577)
That _shouldn't_ be ambiguous, `false` is a valid JSON document according to specification, but not all parsers are compliant.

There's some interesting examples of ambiguities here: https://seriot.ch/projects/parsing_json.html

Re:A love letter to the CSV format by recursive on Thursday March 27, 2025 @03:48PM (#43497381)
Trailing commas, comments, duplicate key names, for a few examples.
Re:A love letter to the CSV format by int_19h on Thursday March 27, 2025 @06:10PM (#43498771)
Trailing commas and comments are plainly not standard JSON under any definition. There are standards that include them which extend JSON, sure, but I'm not aware of any JSON library that emits this kind of stuff by default.
Re:A love letter to the CSV format by recursive on Thursday March 27, 2025 @06:16PM (#43498823)
I'm not aware of any CSV library that doesn't follow RFC4180 by default, and yet... this whole thread.
Re:A love letter to the CSV format by gopher_space on Wednesday March 26, 2025 @04:37PM (#43487016)
There is a clear standard and it's usually written on an old Word '97 doc in a local file server. Using CSV means that you are the compatibility layer, and this is useful if you need firm control or understanding of your data.

If that sounds like a lot of edge-case work keep in mind that people have been doing this for more than half a century. Lots of examples and notes you can steal.

Re:A love letter to the CSV format by Kinrany on Wednesday March 26, 2025 @07:26PM (#43488689)
Re:A love letter to the CSV format by pasc1878 on Thursday March 27, 2025 @07:21AM (#43492430)
And does Excel fully comply and more imprtantly tell you when the CSV file is wrong
Re:A love letter to the CSV format by recursive on Thursday March 27, 2025 @03:47PM (#43497374)
No. Excel's fault. Not CSV. There are plenty of busted CSV parsers (and serializers) too.
Re:A love letter to the CSV format by gthompson512 on Wednesday March 26, 2025 @04:49PM (#43487152)
> It's just that people tend to use specialized tools for encoding and decoding it instead of like ",".join(row) and row.split(",")

You really super can't just split on commas for csv. You need to handle the string encodings since records can have commas occur in a string, and you need to handle quoting since you need to know when a string ends and that string may have internal quote characters. For either format unless you know your data super well you need to use a library.

Re:A love letter to the CSV format by benwilber0 on Wednesday March 26, 2025 @05:17PM (#43487406)
Right, obviously.
Re:A love letter to the CSV format by pasc1878 on Thursday March 27, 2025 @07:21AM (#43492426)
Yes but people don't
Re:A love letter to the CSV format by juliansimioni on Wednesday March 26, 2025 @03:03PM (#43485679)
What happens when you need to encode the newline character in your data? That makes splitting _either_ CSV or LDJSON files difficult.
Re:A love letter to the CSV format by koolba on Wednesday March 26, 2025 @03:12PM (#43485805)
The new line character in a JSON string would always be \n. The new line in the record itself as whitespace would not be acceptable as that breaks the one line record contract.

Remember that this does not allow arbitrary representation of serialized JSON data. But it allows for any and all JSON data as you can always roundtrip valid JSON to a compact one line representation without extra whitespace.

Re:A love letter to the CSV format by mananaysiempre on Wednesday March 26, 2025 @03:11PM (#43485794)
When you need to encode the newline character in your data, you say \n in the JSON. Unlike (the RFC dialect of) CSV, JSON has an escape sequence denoting a newline and in fact requires its use. The only reason to introduce newlines into JSON data is prettyprinting.
Re:A love letter to the CSV format by nmz on Thursday March 27, 2025 @12:13AM (#43490348)
It's tricky, but simple enough, RFC states that " must be used, escaping a " is done with 2 "". This makes knowing what a record is difficult, since you must keep a variable that keeps the entire string.

How do you do this simply? you read each line, and if there's an uneven number of ", then you have an incomplete record and you will keep all lines until there is an odd number of ". after having the string, parsing the fields correctly is harder but you can do it in regex or PEGs or a disgusting state machine.

Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @05:09AM (#43491631)
Actually even whitespace-separated json would be a valid format and if you forbid json documents to be a single integer or float then even just concatenating json gives a valid format as JSON is a prefix free language.

That is[0] if a string s is a valid JSON then there is no substring s[0..i] for i < n that is a valid json.

So you could just consume as many bytes you need to produce a json and then start a new one when that one is complete. To handle malformed data you just need to throw out the partial data on syntax error and start from the following byte (and likely throw away data a few more times if the error was in the middle of a document)

That is [][]""[][]""[] is unambiguos to parse[1]

[0] again assuming that we restrict ourselves to string, null, boolean, array and objects at the root

[1] still this is not a good format as a single missing " can destroy the entire document.

Re:A love letter to the CSV format by boogheta on Thursday March 27, 2025 @05:57AM (#43491887)
« a single missing " can destroy the entire document » This is basically true for any data format, so really worse argument ever...
Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @11:22AM (#43494590)
In jsonl a modified chunk will lose you at most the removed lines and the two adjacent ones (unless the noise is randomly valid json), in particular a single byte edit can destry at most 2 lines.

utf-8 is also similarly self-correcting and so is html and many media formats.

My point was that in my made-up concatenated json format

[]"""[][][][][][][][][][][]"""[]

and

[]""[][][][][][][][][][][]""[]

are both valid but have differ only for 2 bytes but have entirely different structures.

Also it is a made-up format nobody uses (if somebody were to want this they would likely disallow strings at the root level).

Re:A love letter to the CSV format by packetlost on Wednesday March 26, 2025 @03:13PM (#43485821)
Eh, it really isn't. The format does not lend itself to tabular data, instead the most natural way of representing data involves duplicating the keys N times for each record.
Re:A love letter to the CSV format by koolba on Wednesday March 26, 2025 @03:16PM (#43485865)
You can easily represent it as an array:

    [“foo”,”bar”,123]
That’s as tabular as CSV but you now have optional types. You can even have lists of lists. Lists of objects. Lists of lists of objects…
Re:A love letter to the CSV format by simonw on Wednesday March 26, 2025 @03:43PM (#43486278)
Right - the JSON-newline equivalent of CSV can look like this:

    ["id", "species", "nickname"]
    [1, "Chicken", "Chunky cheesecakes"]
    [2, "Dog", "Wagging wonders"]
    [3, "Bunny", "Hopping heroes"]
    [4, "Bat", "Soaring shadows"]
Re:A love letter to the CSV format by nomel on Wednesday March 26, 2025 @04:25PM (#43486875)
Remove the [] characters and you've invented CSV with excel style quoting.
Re:A love letter to the CSV format by simonw on Wednesday March 26, 2025 @07:23PM (#43488669)
Almost, except the way Excel-style quoting works with newlines sucks - you end up with rows that span multiple lines, so you can't split on newline to get individual rows.

With JSON those new lines are \n characters which are much easier to work with.

Re:A love letter to the CSV format by magicalhippo on Thursday March 27, 2025 @12:55AM (#43490499)
I ended up parsing the XML format instead of the CSV format when handling paste from Excel due to the newlines issue.

CSV seemed so simple but after numerous issues, a cell with both newline and " made me realize I should keep the little hair I had left and put in the work to parse the XML.

It's not great either, with all its weird tags, but at least it's possible to parse reliably.

Re:A love letter to the CSV format by freehorse on Wednesday March 26, 2025 @04:53PM (#43487186)
This misses the point of standardization imo because it’s not possible to know a priori that the first line represents the variable names, that all the rows are supposed to have the same number of elements and in general that this is supposed to represent a table. An arbitrary parser or person wouldn’t know to guess since it's not standard or expected. Of course it would be parsed fine but the default result would be a kind of structure or multi-array rather than tabular.
Re:A love letter to the CSV format by afiori on Thursday March 27, 2025 @05:10AM (#43491649)
application/jsonl+table
Re:A love letter to the CSV format by collinmanderson on Thursday March 27, 2025 @10:30AM (#43494056)
This is the way. jsonl where each row is a json list. It has well-defined standard quoting.

Just like csv you don't actually need the header row either, as long as there's convention about field ordering. Similar to proto bufs, where the field names are not included in the file itself.

Re:A love letter to the CSV format by packetlost on Wednesday March 26, 2025 @03:41PM (#43486243)
You're missing my point: basically nothing spits out data in that format because it's not ergonomic to do so. JSON is designed to represent object hierarchies, not tabular data.
Re:A love letter to the CSV format by koolba on Wednesday March 26, 2025 @04:16PM (#43486758)
JSON was designed to represent any data. There's plenty of systems that spit out data in exact that format because it's the natural way to represent tabular data using JSON serialization. And clearly if you're the one building the system you can choose to use it.
Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @04:18PM (#43486782)
CSV is lists of lists of fixed length.

JSON is lists of lists of any length and groups of key/value pairs (basically lisp S-expressions with lots of unnecessary syntax). This makes it a superset of CSV's capabilities.

JSON fundamentally IS made to represent tabular data, but it's made to represent key-value groups too.

Why make it able to represent tabular data if that's not an intended use?

Re:A love letter to the CSV format by packetlost on Wednesday March 26, 2025 @07:19PM (#43488634)
> JSON is lists of lists of any length and groups of key/value pairs

The "top-level" structure of JSON is usually an object, but it can be a list.

> JSON fundamentally IS made to represent tabular data

No, it's really not. It's made to represent objects consisting of a few primitive types and exactly two aggregate types: lists and objects. It's a textual representation of the JavaScript data model and even has "Object" in the name.

> Why make it able to represent tabular data if that's not an intended use?

It's mostly a question of specialization and ergonomics, which was my original point. You can represent tabular data using JSON (as you can in JavaScript), but it was not made for it. Anything that can represent """data""" and at least 2 nesting levels of arbitrary-length sequences can represent tabular data, which is basically every data format ever regardless of how awkward actually working with it may be.

Re:A love letter to the CSV format by freehorse on Wednesday March 26, 2025 @05:12PM (#43487356)
The fact that json can represent a superset of tabular data structures that csv is specifically designed to represent can be rephrased into that csv is more specialised than json in representing tabular data. The fact that json can also represent tabular data does not mean it is a better or more efficient way to represent that data instead of a format like csv.

In the same way, there are hierarchically structured datasets that can be represented by both json in hierarchical form and csv in tabular form by repeating certain variables, but if using csv would require repeating them too many times, it would be a bad idea to choose that instead of json. The fact that you can do sth does not always make it a good idea to do it. The question imo is about which way would be more natural, easy or efficient.

Re:A love letter to the CSV format by Kinrany on Wednesday March 26, 2025 @07:33PM (#43488750)
> The fact that json can represent a superset of tabular data structures that csv is specifically designed to represent can be rephrased into that csv is more specialised than json in representing tabular data. The fact that json can also represent tabular data does not mean it is a better or more efficient way to represent that data instead of a format like csv.

The reverse is true as well: being more specialized is a description of goals, not advantages.

Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @07:29PM (#43488716)
It's hardly a bad idea to do a list of lists in JSON...

The big advantage of JSON is that it's standardized and you can reuse the JSON infrastructure for more than just tabular data.

Re:A love letter to the CSV format by meepmorp on Wednesday March 26, 2025 @04:53PM (#43487190)
> CSV is lists of lists of fixed length.

I'd definitely put that in my list of falsehoods programmers believe about CSV files.

Re:A love letter to the CSV format by hajile on Wednesday March 26, 2025 @07:13PM (#43488563)
It seems to be indicated by RCF-4180 which says

> This header will contain names corresponding to the fields in the file and should contain the same number of fields as the records in the rest of the file

But of course, CSV is the wild west and there's no guarantee that any two encoders will do the same thing (sometimes, there's not even a guarantee that the same encoder will do the same thing with two different inputs).

[0] https://www.ietf.org/rfc/rfc4180.txt

Re:A love letter to the CSV format by HelloNurse on Thursday March 27, 2025 @05:04AM (#43491615)
You should know that "should" isn't very binding.

Headers should have as many rows as possible that contain data items for their column and data items in a row should have a header for the respective columns, but real CSV files should be assumed to have incomplete or variable length lines.

Re:A love letter to the CSV format by hajile on Thursday March 27, 2025 @10:08AM (#43493841)
NOTHING is very binding about the CSV spec and that's the biggest problem with CSV.
Re:A love letter to the CSV format by timacles on Wednesday March 26, 2025 @06:48PM (#43488347)
CSV is a text file that might have commas in it
Re:A love letter to the CSV format by miningape on Wednesday March 26, 2025 @08:55PM (#43489304)
yeah if I had a cookie for every time I've had to deal with this I'd have maybe 10 cookies - it's not a lot but it's more than it should be.
Re:A love letter to the CSV format by kccqzy on Wednesday March 26, 2025 @05:18PM (#43487416)
JSON is designed to represent JavaScript objects with literal notation. Guess what, an array of strings or an array of numbers or even an array of mixed strings and numbers is a commonly encountered format in JavaScript.
Re:A love letter to the CSV format by kazinator on Wednesday March 26, 2025 @07:48PM (#43488865)
A format consisting of newline-terminated records, each containing comma-separated JSON strings would be superior to CSV.

It could use backslash escapes to denote control characters and Unicode points.

Everyone would agree exactly on what the format is, in contrast to the zoo of CSV variants.

It wouldn't have pitfalls in it, like spaces that defeat quotes

  RFC CSV         JSON strings
  a,"b c"         "a", "b c"
  a, "b c"        "a", " \" b c\""
oops; add an innocuous-looking space, and the quotes are now literal.
[deleted]
Re:A love letter to the CSV format by kazinator on Wednesday March 26, 2025 @11:26PM (#43490117)
"Any JSON primitive" does add a few requirements not semantically comparable to CSV, like numbers that are numbers, and keywords true, false, none.

When these syntaxes are parsed into objects, either the type info has to be retaind, or some kind of attribute tag, so they can be output back to the same form.

> make it so any consumer can parse it by splitting on newline and then ...

There is something like that called JSON-lines. It has a .org domain 'n' everything:

https://jsonlines.org/

Re:A love letter to the CSV format by lgas on Wednesday March 26, 2025 @04:41PM (#43487058)
Typing isn't optional in JSON, every value has a concrete type, always.
Re:A love letter to the CSV format by gghffguhvc on Wednesday March 26, 2025 @05:03PM (#43487284)

  [
   [“header1”,”header2”],
   [“1.1”, “”],
   [7.4, “2022-01-04”]
  ]
Re:A love letter to the CSV format by Sohcahtoa82 on Thursday March 27, 2025 @11:59AM (#43494996)
...and?

I see an array of arrays. The first and second arrays have two strings each, the last one has a float and a string. All those types are concrete.

Let's say those "1.1" and 7.4 values are supposed to be version strings. If your code is only sometimes putting quotes around the version string, the bug is in your code. You're outputting a float sometimes, but a string in others. Fix your shit. It's not your serialization format that's the problem.

If you have "7.4" as a string, and your serialization library is saying "Huh, that looks like a float, I'm going to make it a float", then get a new library, because it has a bug.

Re:A love letter to the CSV format by lelandbatey on Thursday March 27, 2025 @03:30PM (#43497177)
Types at the type layer are not the same as types at the semantic layer. Sure every type in the JSON level has a "strong type" but the semantic meaning of the contents of e.g. a string are usually not expressable in pure JSON. So it is with CSV; you can think of every cell in CSV as containing a string (series of bytes) with it being up to you to enforce the semantics atop those bytes. JSON gives you a couple extra types, and if you can fit things into those types well, then that's great, but for most data concrete semantically meaningful data you won't be able to do that and you'll end up in a similar world to CSVs.
Re:A love letter to the CSV format by klysm on Wednesday March 26, 2025 @05:44PM (#43487729)
You serialize the keys on every row which is a bit inefficient but it’s a text format anyway
Re:A love letter to the CSV format by zeroimpl on Wednesday March 26, 2025 @08:46PM (#43489232)
Space-wise, as long as you compress it, it's not going to make any difference. I suspect a JSON parser is a bit slower than a CSV parser, but the slight extra CPU usage is probably worth the benefits that come with JSON.
Re:A love letter to the CSV format by nmz on Thursday March 27, 2025 @12:22AM (#43490374)
This is simply not true, parsing json v csv is a difference of thousands of lines.
Re:A love letter to the CSV format by magicalhippo on Thursday March 27, 2025 @01:05AM (#43490542)
> JSON [...] with one line per record

Couple of standards that I know of that does this, primarily intended for logging:

https://jsonlines.org/

https://clef-json.org/

Really easy to work with in my experience.

Sure some space is usually wasted on keys but compression takes care of that.

Re:A love letter to the CSV format by kec on Thursday March 27, 2025 @09:10AM (#43493236)
Until you have a large amount of data & need either random access or to work on multiple full columns at once. Duplicated keys names mean it's very easy for data in jsonlines format to be orders of magnitude larger than the same data as CSV, which is incredibly annoying if your processing for it isn't amenable to streaming.