Comment on Show HN: Npm module that makes easy to convert JSON to CSVComments−codezero9yCool, I immediately wondered if you handled a lot of the tricky CSV things like quotes and internal commas, it looks like it does a good job.Comparing against Numbers (probably a bad comparison?) I am seeing one slightly different result:If I have a field that is "hehe"It's encoded as ""hehe""It looks like Numbers adds the enclosing quotes:"""hehe"""I only see enclosing quotes if there's a comma:"hehe,hehe" -> """hehe,hehe"""Anyhow, I'm not sure what the "correct" thing to do here is, if there is one, just a heads up!−chc9yCSV is pretty poorly standardized, but if you're going by RFC-4180, Numbers is definitely right, due to the interaction of two rules:* double quotes aren't allowed inside a field that isn't double-quoted* double-quotes that do appear in a field have to be escaped by preceding them with another double quote.So by RFC-4180, I'm pretty sure ""hehe"" shouldn't be possible, and the way to represent "hehe" with the quotes is """hehe""".−codezero9yCool, yep, thanks for pointing out the RFC. I don't envy anyone making CSV parsers and basically assume they won't work when I need to use them :)−kauegimenesOP9yHere is all the logic related to this behavior: https://github.com/kauegimenes/jsonexport/blob/master/lib/co...
Comments
Cool, I immediately wondered if you handled a lot of the tricky CSV things like quotes and internal commas, it looks like it does a good job.
Comparing against Numbers (probably a bad comparison?) I am seeing one slightly different result:
If I have a field that is "hehe"
It's encoded as ""hehe""
It looks like Numbers adds the enclosing quotes:
"""hehe"""
I only see enclosing quotes if there's a comma:
"hehe,hehe" -> """hehe,hehe"""
Anyhow, I'm not sure what the "correct" thing to do here is, if there is one, just a heads up!
CSV is pretty poorly standardized, but if you're going by RFC-4180, Numbers is definitely right, due to the interaction of two rules:
* double quotes aren't allowed inside a field that isn't double-quoted
* double-quotes that do appear in a field have to be escaped by preceding them with another double quote.
So by RFC-4180, I'm pretty sure ""hehe"" shouldn't be possible, and the way to represent "hehe" with the quotes is """hehe""".
Cool, yep, thanks for pointing out the RFC. I don't envy anyone making CSV parsers and basically assume they won't work when I need to use them :)
Here is all the logic related to this behavior: https://github.com/kauegimenes/jsonexport/blob/master/lib/co...