5 ms·
One popular alternative (useful if your data has nested dicts or arrays) is to use newline separated json. This avoids having to encode or parse the whole datas
by stingraycharles 5y ago
One popular alternative (useful if your data has nested dicts or arrays) is to use newline separated json. This avoids having to encode or parse the whole dataset as a single object, but rather line-by-line, which works nicely with large datasets.
- philwelch 5y agoThis helps but repeating the keys on each line is still a pain.
- masklinn 5y agoArrays are valid json values.
- philwelch 5y agoBut that would be a very irregular way to use JSON.
- masklinn 5y agoNot even remotely.
- philwelch 5y agoIt’s not irregular to represent a list of typed objects in JSON as an array of arrays in which the first array is the array of keys in the same order as the corresponding values? Is there a JSON serialization library that actually uses this pattern? I’m not asking to be argumentative, but I genuinely like the idea and would be pleasantly surprised to see it.
- mattewong 5y agoI never really understood why anyone thinks this is a good idea. Popular, maybe. Smart? Not so sure. Instead of just modifying your parser, you change your entire input format to be incompatible with what most of the rest of the world uses (standard JSON). I get it, it requires slightly more technical skill / effort / etc to implement a proper streaming JSON parser (which BTW will perform WAY better in terms of speed and memory) instead of just writing "my_data.split('\n')". But, there are pre-existing libraries that already do that, and a one-time tiny bit of extra work, to open up a capability that you can reuse anywhere in your stack, seems to be a much better option than a lifetime of incompatibility with standard JSON.