3 ms·
The reason why it works with JSON is that JSON strings are not allowed to contain real newline characters. The spec says they have to be escaped. So newline wor
by iaabtpbtpnn 5y ago
The reason why it works with JSON is that JSON strings are not allowed to contain real newline characters. The spec says they have to be escaped. So newline works as a field delimiter, but only because JSON excludes it from field values.
- BugsJustFindMe 5y agoEvery compactible format allows physically marking line breaks. JSON isn't very special in this regard.
- iaabtpbtpnn 5y agoI am not familiar with the phrase "compactible format", but it's not about allowing, it's about requiring. I can be sure that my JSON message contains no literal newlines, because if it did then it wouldn't be JSON. Contrast with any format that allows literal newlines in values, for example CSV...
- BugsJustFindMe 5y ago> I am not familiar with the phrase "compactible format" You know how C++ lines end with semicolons (or how Javascript lines _can_ end that way if you want)? And how that means you can put all of the instructions in a function on one hyperlong line? That's compactible. Any format where you are able to smush all the lines within a functional group together into one long line is compactible. You can use the ASCII record separator character instead of newlines if you prefer. Separating records without colliding with newlines is literally what it's for.
- zvr 5y agoIn the two languages mentioned, semicolons play a different role: statement terminator vs. statements separator .
- recursive 5y agonewlines are explicitly allowed in json. https://www.json.org/json-en.html https://www.json.org/json-en.html See "whitespace". In order to be used in ndjson, valid json must have its newlines removed.
- nicoburns 5y agoRight, but newlines are not semantically meaningful in JSON. JSON with newlines stripped naively will parse identically to JSON containing those newlines.