4 ms·
CSV works for simple cases. It is trivial to parse, you shouldn't even need a library. It there are many "what ifs" like in the posted article. You probably n
by huherto 12y ago
CSV works for simple cases. It is trivial to parse, you shouldn't even need a library.
It there are many "what ifs" like in the posted article. You probably need another format like JSON (preferably) or XML.
- EpicEng 12y agoYet in the real world you don't often have such luxury. Often times that inconsistent CSV file that you have to parse is not of your own creation. It comes from some other data source, or perhaps you have multiple data sources spitting out their own variants. You just need to get the job done, and splitting on ',' won't work.
- chrismcb 12y agoWell a lot of times you are reading in a csv file given to you by someone else. You can't expect it to be "simple" and you need to parse it correctly
- mholt 12y agoJSON is arguably more complex than CSV. Though it is at least well-defined (mostly). However, that doesn't excuse sloppy CSV writers.
- daigoba66 12y agoOff topic, but why JSON over XML? What are the technical advantages for using JSON instead of XML (and don't say anything about "human readable"). If you're consuming the data with JavaScript, I'll grant you that JSON has quite an edge. But most every language has standard libs for XML. Both are easy to parse, but XML is easier to validate given a schema definition.
- bartonfink 12y agoBecause of closing tags, XML is approximately twice as noisy as JSON encoding. If response sizes and the network traffic they entail are a concern, JSON is worth considering. If response sizes + validation are necessary, something like Protocol Buffers or Thrift may also fit, as they are widely supported as well.
- skybrian 12y agoJSON is considerably more compact, especially if you use lists instead of maps. For a list of numbers, there is only one character of overhead per item. For a list of strings, it's three characters per item. Of course you can embed comma-separated lists in XML, but with JSON it will parse them for you. (And of course it's not as good as a protobuf, but not bad for a text format.)
- tetha 12y agoIf your data touches the network, conform xml parsing is an attack vector (billion laughs, external entity exploits, ...) and non-conform xml parsing ends up being a headache. Even more, the sheer absurd complexity of xml contains so much stuff, who knows how many more exploits by specification are in there.