3 ms·
JSON is great for sending javascript objects over the network. However, the way most people use it, they'd benefit from switching to CSV files instead. JSON has
by nobodysfool 13y ago
JSON is great for sending javascript objects over the network. However, the way most people use it, they'd benefit from switching to CSV files instead. JSON has a lot of overhead (each instance of each object has to have a name), but it's better than xml.
- Stratoscope 13y agoThat's true, but the JSON data is sent over the wire with gzip compression. All those repeated names compress out very nicely. CSV is still probably more compact than JSON even when compressed, but the difference isn't nearly as much as you'd expect from the raw textual version. Of course it gets expanded back to the full text in the browser, but that gets parsed and discarded right away. When I read CSV in JavaScript, for convenience I usually end up converting it to in-memory objects that resemble the JSON object that I would have downloaded otherwise. So at least in that case there isn't much difference in memory use either.
- mpyne 13y agoAlso browsers are much more likely to be able to optimize the parsing of JSON back into a DOM than they are to be able to optimize the JS that would be used to parse the CSV.
- iso8859-1 13y agoCSV files are simply lists of tuples. You can do lists of lists in JSON. Your overhead will be two characters (opening/closing braces) per tuple (one if you skip the newline, which you can't skip in CSV), plus a dozen characters for the whole file. I don't think that's a lot of overhead, seeing that you get the benefits of a format that is actually standardized. Example (CSV): name,age James,32 Nina,10 Helga,90 JSON: {"fields":["name","age"], "content":[ ["James",32], ["Nina",10], ["Helga",90] ]} Don't tell me it's harder to parse, cause you'd have to do the index→fieldname conversion in CSV too.
- teyc 13y agoCSV isn't standardized. http://en.wikipedia.org/wiki/Comma-separated_values#Lack_of_a_standard http://en.wikipedia.org/wiki/Comma-separated_values#Lack_of_... There are a lot of questions regarding use of quotation, new lines etc. JSON's standard is that it should be able to be eval'd by javascript interpreter. Even then, date handling is less than ideal.