95 points · by tambourine_man · 10y ago · 53 comments
There are already streaming JSON parsers/serializers, why not just use (or write) one of those instead of inventing yet another file format?
There's also http://ndjson.org/ and http://jsonlines.org/
It only says "Semantically a CSJ file is an array of JSON objects which share a common set of keys." You used your knowledge of how these representations usually work to infer that the first line contains a list of keys for the remaining lines.
Some obvious questions for a table spec include: 1) must those keys be strings? 2) Are duplicate keys allowed? 3) Can different rows have a different number of columns? Or must the writer generate null fields?
FWIW, I've used JSON Lines for my own work. It's very easy to read a line and (in Python), json.loads(line). How should I parse this "JSON without [ and ]"?
There's not a built-in function for it. Either I have to write my own JSON tokenizer, or I have to terminate the string with '[' and ']' and parse that. Both are much more complicated than using JSON Lines? You'll notice they only gave output generation timing numbers, not input parsing.
If a JSON-based table format is important, why not layer those same table semantics on top of JSON Lines, rather than make a format which is harder to read?
Do you really believe that this is harder to read than JSON lines? We use both, and I've never heard a user complain that CSJ is hard to read, but the JSON lines has a lot of clutter.
{"age": 45, "name": "Kirit Sælensminde", "job": "Minister Without Portfolio"}
{"job": null, "age": 5, "name": "Freyja Sælensminde"}
That seems fine for a low number of columns, but gets much harder as the column count goes up. Especially so as you lose control of the key order in the line.There is nothing inherently preventing you from writing an almost identically performing streaming JSON parser or serializer.
With this proposed format you only need to parse the object definition once and you also get the ordering fixed. From then on you need only validate each field in each line as being legal and you can build your object quite fast.
This format saves probably half the network bandwidth, half or more in memory requirements, and more than half the cpu complexity in parsing and getting your final objects instantiated. That's pretty good.
Remember the goal isn't to replace JSON. It's to replace CSV. JSON and CSV have different goals. This is simply a JSON structure built to meet the same goals as CSV. It seems to do that quite nicely and can use existing JSON parsers internally to do it. Pretty nifty.
I've been in arguments with customers before where they complained we were quoting strings, and CSV files shouldn't have quotes, and it would have been nice to say "We're using CSJ, please just parse that way".
I think the name is perhaps misleading though, as it sounds more like it's a variant of JSON than a formalization of CSV. Perhaps "JSON flavored CSV" would be more appropriate?
What about "Comma-Separated JSON Values"? CSJV!
Stick with JSON document per line.
why not have all possible object definitions in the header and data as a single huge array?
Basically you have a TYPE (fixed width, eg. 16 bits), a LENGTH (again fixed) and a VALUE which is simply a stream of bytes that goes on for LENGTH bytes and is interpreted based on what TYPE it is. You can nest your fields and get very creative in quite a compact way.
One could represent a JSON document with TLV by adding an associative map between the field names and their type numbers, then stream away.
I always loved the simplicity of TLV. Though nowadays, I'm not sure this has much of an advantage over gzipped JSON.
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/curr...
https://ronaldduncan.wordpress.com/2009/10/31/text-file-form...
https://news.ycombinator.com/item?id=7474600
But, it suffered from not having designated keys on common keyboards, therefore it wasn't obviously necessary for plain text editors to support. Meanwhile, everyone uses plain text editors for everything --even if it means jumping through hoops full of exceptions and corner cases to pretend they can handle more than plain text.
https://github.com/ServiceStack/ServiceStack.Text/wiki/JSV-F...
Which is just JSON with CSV-escaping which is ends up being faster, more concise and more human-friendly since quotes are only necessary when using special delimiter chars. It's just not as interoperable or ubiquitous as JSON so only an option when you control both ends.
To be honest, what I didn't like is the tone of the article. It is just that this statement is wrong: "But the problem is that CSV isn't really a well defined file format with a well defined syntax." There is RFC 4180.
But if it became popular, this format seems easy to support.
the reason json is popular is because it's widely used and is easily parsed (without having to call any extra libraries).
standardizing this would mean accepting upon a complete working alternate that'd work everywhere just akin to json (plus the added perks), which will take a lot of (dis)agreement, especially given that there are already a dozen other standards trying to replace json.
given you don't have that constraint there are much better options (json lines, avro, parquet, protobufs...)
Especially with the CSV in RFC 4180, which among other things requires a CRLF.