Live data from Hacker News

A love letter to the CSV format

github.com

261–270 of 711 posts

Re: A love letter to the CSV format

#261

Earlier quoted context omitted.

Can you import .jsonl files into Google sheets or excel natively?

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.

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

#262
post #169

Earlier quoted context omitted.

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?

> CSV is lists of lists of fixed length. I'd definitely put that in my list of falsehoods programmers believe about CSV files.

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

#263

Earlier quoted context omitted.

Decimal separators being commas in some locales?

Commas are commonly used in text, too.

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

#264
the simplicity is underappreciated because people don't realise how many dumb data engineers there are. i'm pretty sure most of them can't unpack an xml or json. people see a csv and think they can probably do it themselves, any other data format they think 'gee better buy some software with the integration for this'.

Re: A love letter to the CSV format

#265
post #163

Earlier quoted context omitted.

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 p…

It falls down under very large integers -- think large valid uint64_t values.

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

#266
post #7

I'm not really sure why "Excel hates CSV". I import into Excel all the time. I'm sure the functionality could be expanded, but it seems to work fine. The bit of the process I would like improved is nothing to do with CSV - it's that the exporting programs sometimes rearrange the order of fields, and you have to accommodate that in Excel after the import. But since you can have named columns in Excel (make the data in…

I have repeatedly seen people getting the spreadsheets altered by excel, and in general a lot of troubles due to localisation reasons. Sometimes these changes can be subtle and be hard to spot until somebody tries to troubleshoot what went wrong down the line.

It works better if you click to "import the data" instead of just opening the csv file with it, and if you then choose the right data types. But having to do this everytime to make it work is really annoying, esp when you have a lot of columns, plus people can easily get confused with the data types. I have never seen that much confusion eg with macos's numbers.

Re: A love letter to the CSV format

#267
post #65

The argument against JSON isn't very compelling. Adding a name to every field as they do in their strawman example isn't necessary. Compare this CSV field1,field2,fieldN "value (0,0)","value (0,1)","value (0,n)" "value (1,0)","value (1,1)","value (1,n)" "value (2,0)","value (2,1)","value (2,n)" To the directly-equivalent JSON [["field1","field2","fieldN"], ["value (0,0)","value (0,1)","value (0,n)"], ["value (1,0)","…

> the directly-equivalent JSON [["field1","field2","fieldN"], ["value (0,0)","value (0,1)","value (0,n)"], ["value (1,0)","value (1,1)","value (1,n)"], ["value (2,0)","value (2,1)","value (2,n)"]] I think it's a big stretch to use that JSON for comparison. In practice, one is much more likely to see this: [ { "field1": "value (0,0)", "field2": "value (0,1)", "fieldN": "value (0,n)" }, { "field1": "value (1,0)", "fiel…

While most people would prefer the second version, the first version is also valid JSON and will definitely see use when you want/need JSON but want to reduce data over the wire though you'd probably still see a wrapper object like:

    {
      headers: ["field1","field2","fieldN"],
      values: [["value (0,0)","value (0,1)","value (0,n)"],
       ["value (1,0)","value (1,1)","value (1,n)"],
       ["value (2,0)","value (2,1)","value (2,n)"]]
    }

Re: A love letter to the CSV format

#268
post #169

Earlier quoted context omitted.

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.

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?

> 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

#269
post #171
post #154

Earlier quoted context omitted.

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"]

Remove the [] characters and you've invented CSV with excel style quoting.

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

#270
post #166
post #63

Earlier quoted context omitted.

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…

> 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.

It's widely, but inconsistently, supported. The behavior of importers varies a lot, which is generally not the case for JSON.
Post reply on HN