News for hackers. Stuff that matters.
Re:Ask HN: Who built XMLHttpRequest at Microsoft in 1999? by nobodysfool on Monday April 29, 2013 @01:44PM (#5627605)
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.
Re:Ask HN: Who built XMLHttpRequest at Microsoft in 1999? by Stratoscope on Monday April 29, 2013 @03:18PM (#5628072)
That'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.

Re:Ask HN: Who built XMLHttpRequest at Microsoft in 1999? by mpyne on Monday April 29, 2013 @08:59PM (#5629859)
Also 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.
Re:Ask HN: Who built XMLHttpRequest at Microsoft in 1999? by iso8859-1 on Monday April 29, 2013 @03:51PM (#5628268)
CSV 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.
Re:Ask HN: Who built XMLHttpRequest at Microsoft in 1999? by teyc on Wednesday May 08, 2013 @09:48PM (#5678306)
CSV isn't standardized. 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.