News for hackers. Stuff that matters.
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