4 ms·
This. I mean if an API sends invalid JSON you can't parse it...
by k__ 9y ago
This.
I mean if an API sends invalid JSON you can't parse it...
- masklinn 9y agoJSON is pretty extensively specified. Saying that CSV is not is generous.
- vageli 9y agoNot a standard _per se_ [0] but goes to show that some level of effort has been applied to CSV standardization. [0]: https://tools.ietf.org/html/rfc4180 https://tools.ietf.org/html/rfc4180
- justinclift 9y agoYeah, that's the most commonly referenced standard. Approaching it from a database perspective (eg sqlitebrowser.org), where we need to both import and export CSV's... it can be tricky. For example, if an imported CSV file has two commas ",," that generally indicates an empty field. But, does that mean an empty string? Or does it mean we should use the default value for the field (as per database spec)? That specific case can be handled by a user preference on the import/export dialog ("What to do with empty fields?"). Other's less so. For example, database fields can contain data types (eg images, binary blobs) that have no representation defined in the RFC. Literally any decision about how to encode them is going to be non-standard. Ugh. There really needs to be a follow up RFC that specifies useful, practical things to tighten up the gaps.
- dmitriid 9y agoWhy is parsing JSON a minefield then? ;) http://seriot.ch/parsing_json.php http://seriot.ch/parsing_json.php
- masklinn 9y agoBecause "pretty extensively specified" does not mean "fully specified and perfectly implemented". The equivalent page for CSV would not have an end.
- arghwhat 9y agoWhere is the minefield? In accepting things that are not JSON, such as trailing commas and comments? That's silly. Everything blue and yellow in that matrix is entirely OK and should be green ("undefined" means "anything goes", and the spec specifically allows accepting more than JSON, so "should have failed" is bogus). That leaves a few parser bugs in form of orange and red, but they're corner cases (like surrogate pairs or 10000 nested arrays) and fixable.
- paulddraper 9y agoBut.... * Do you accept trailing commas? * Do you accept multiline comments? * Do you accept single line comments? * Do you accept literal newlines in strings? * Do you accept single quotes in place of double quotes? * Do you accept integers over 8 bytes? * Do you autodetect Unicode encoding? * Do you accept numbers with leading zeros? * Do you accept numbers with a leading plus sign? * Do you accept NaN? * Do you accept non-quoted object keys? * Do you accept duplicate object keys? In other words, > A JSON parser MAY accept non-JSON forms or extensions. https://tools.ietf.org/html/rfc7159 https://tools.ietf.org/html/rfc7159
- arghwhat 9y agoAs the quote states, none of that would be JSON. Thus, if you have a document that contains that, it is no longer JSON. A parser may accept things that are not JSON, but that's rather irrelevant. JSON does not have comments, support trailing comments, single quotes, etc. etc. etc.
- paulddraper 9y agoCertainly. And some programs may accept things are not CSVs.
- arghwhat 9y agoThe vast majority of programs support things that are not CSVs. :) (Couldn't help it.)