4 ms·
And here I am wrapping my results in a result object line a newb: { results: [ { ... }, { ... }, { ... }
by jasonpeacock 5y ago
And here I am wrapping my results in a result object line a newb:
{
results: [
{ ... },
{ ... },
{ ... }
]
}
- cosmotic 5y agoor just: [ { ... }, { ... }, { ... }, ]
- iddqd 5y agoLine separated JSON has its uses, for example when streaming data.
- BugsJustFindMe 5y agoThe only reason people care about newlines for a stream is because they've arbitrarily chosen to fetch bytes from the stream until the next newline sequence (readline instead of read). But you could just as easily look for a different sequence, like the ASCII record separator character which was invented exactly for this task, and then you wouldn't have to destructively strip newlines from your input.
- nerdponx 5y agoI'll switch from \n to \x1E when cat, head, text editors, etc. start supporting the latter as a synonym for the former.
- morelisp 5y agoWe tell our customers our streaming API uses jsonlines for documentation purposes, but we actually just decode in a loop until EOF, and 400 at the first decode error. No separators necessary at all.
- amelius 5y agoOk, but what if you want to transmit two streams? You'd get something like Interlaced-newline-delimited-JSON. And so the list of required file formats knows no end.
- SahAssar 5y agoIf you're transmitting two streams you use two streams to transmit. I don't see the problem?
- amelius 5y agoTwo streams over the same channel.
- SahAssar 5y agoI don't see why this is a problem with ndjson anymore than it is a problem with other stream text encodings (like CSV). ndjson seems to be about how to format the content of the stream, not about how to multiplex multiple streams over a single channel. Use http2, zeromq, raw tcp or whatever else you like for that.
- codesnik 5y agowell, jsonlines works extremly well for gigabytes of short json objects. You can mix and match usual unix tools, or simple scripts with just "read" in a loop, and you can parse each json object without worrying it'll take all your memory. jq can convert arrays to json lines and back. I love the format.