2 ms·
This is not a good replacement for CSV. It is better to just use regular JSON for that. If you have a file containing this: ["Name", "Session", "Score", "Co
by crdoconnor 11y ago
This is not a good replacement for CSV. It is better to just use regular JSON for that.
If you have a file containing this:
["Name", "Session", "Score", "Completed"]
["Gilbert", "2013", 24, true]
["Alexa", "2013", 29, true]
["May", "2012B", 14, false]
["Deloise", "2012A", 19, true]
And it gets chopped in half (a problem that is not that uncommon), you will get this:
["Name", "Session", "Score", "Completed"]
["Gilbert", "2013", 24, true]
["Alexa", "2013", 29, true]
Which is still valid. This will cause missing data rather than a clear error message. May and Deloise may end up not getting their scores and there's a good chance nobody will notice.
By contrast when the file is represented as regular JSON:
[
["Name", "Session", "Score", "Completed"],
["Gilbert", "2013", 24, true],
["Alexa", "2013", 29, true],
["May", "2012B", 14, false],
["Deloise", "2012A", 19, true]
]
(not a completely ideal representation, but you get the picture)
Chopping this in half will give you a clear error, forcing the developer to recover from it before continuing.
Same principle as strong vs. weak typing.
Individual JSON snippets in lines are a good replacement for plain text-only logs of indeterminate length, however.
- asdfaoeu 11y agoIt seems he's going for the streaming aspect of the file. While that is indeed possible with your format it does require a json library that supports it.
- nulltype 11y agoRegular CSV also has that "problem". Being able to cut the file into pieces is actually really useful when you want to, for instance, process each piece on a different computer. Line-delimited JSON preserves that advantage.
- gkop 11y agoExactly. If JSONL takes off, I'd be glad to use it instead of YAML for streaming serialization/deserialization purposes, if only because JSONL is more space efficient.
- waxjar 11y agoAn end of file delimiter would do just as well and has a major benefit: existing JSON parsers can be used without considering the whole file as a giant JSON object. Most JSON parsers simply parse the JSON string and represent it as an object in memory. You don't want to do that for very big files. Stream based parsers avoid this problem, but are more complicated to work with.