4 ms·
Actually even whitespace-separated json would be a valid format and if you forbid json documents to be a single integer or float then even just concatenating js
by afiori 2y ago
Actually even whitespace-separated json would be a valid format and if you forbid json documents to be a single integer or float then even just concatenating json gives a valid format as JSON is a prefix free language.
That is[0] if a string s is a valid JSON then there is no substring s[0..i] for i < n that is a valid json.
So you could just consume as many bytes you need to produce a json and then start a new one when that one is complete. To handle malformed data you just need to throw out the partial data on syntax error and start from the following byte (and likely throw away data a few more times if the error was in the middle of a document)
That is [][]""[][]""[] is unambiguos to parse[1]
[0] again assuming that we restrict ourselves to string, null, boolean, array and objects at the root
[1] still this is not a good format as a single missing " can destroy the entire document.
- boogheta 2y ago« a single missing " can destroy the entire document » This is basically true for any data format, so really worse argument ever...
- afiori 2y agoIn jsonl a modified chunk will lose you at most the removed lines and the two adjacent ones (unless the noise is randomly valid json), in particular a single byte edit can destry at most 2 lines. utf-8 is also similarly self-correcting and so is html and many media formats. My point was that in my made-up concatenated json format []"""[][][][][][][][][][][]"""[] and []""[][][][][][][][][][][]""[] are both valid but have differ only for 2 bytes but have entirely different structures. Also it is a made-up format nobody uses (if somebody were to want this they would likely disallow strings at the root level).