<div dir="ltr">FWIW, pyline could produce streaming JSON w/ json.dumps(indent=0),<div>but because indent>0, there are newlines.<br><div><br></div><div><div> pydoc json | pyline '{"a":l} if "json" in l.lower() else None' -O json</div></div><div> pydoc json | pyline -r '.*JSON.*' 'rgx and line' -O json </div><div><br></div><div>It's a similar issue:</div><div>what are good default JSON encoding/decoding settings?</div><div><br></div><div> # loads/JSONDecoder</div><div> file.encoding # UTF-8<br></div><div> object_pairs_hook</div><div> object_hook</div><div><br></div><div> # dumps/JSONEncoder</div><div> file.encoding # UTF-8<br></div><div> cls</div><div> separators</div><div> indent</div><div><br></div><div>- [ ] ENH: pyline: add 'jsonlines' as an {output,} format</div><div><br></div><div><br></div><div>From <a href="https://twitter.com/raymondh/status/842777864193769472">https://twitter.com/raymondh/status/842777864193769472</a> :</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">#python tip: Set separators=(',', ':') to dump JSON more compactly.<br>>>> json.dumps({'a':1, 'b':2}, separators=(',',':'))<br>'{"a":1,"b":2}'</blockquote><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 27, 2017 at 3:46 PM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">This is a better link: <a href="https://en.m.wikipedia.org/wiki/JSON_Streaming" target="_blank">https://en.m.wikipedia.<wbr>org/wiki/JSON_Streaming</a></div><div class="gmail-HOEnZb"><div class="gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mar 27, 2017 3:45 PM, "David Mertz" <<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">The format JSON lines (<a href="http://jsonlines.org/" target="_blank">http://jsonlines.org/</a>) is pretty widely used, but is an extension of JSON itself. Basically, it's the idea that you can put one object per physical line to allow incremental reading or spending of objects.<div dir="auto"><br></div><div dir="auto">It's a good idea, and I think the `json` module should support it. But it definitely doesn't belong in `pathlib`.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mar 27, 2017 3:36 PM, "Paul Moore" <<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 27 March 2017 at 17:43, Bruce Leban <<a href="mailto:bruce@leban.us" target="_blank">bruce@leban.us</a>> wrote:<br>
> the ability to read one json object from the input rather than reading the<br>
> entire input<br>
<br>
Is this a well-defined idea? From a quick read of the JSON spec (which<br>
is remarkably short on details of how JSON is stored in files, etc)<br>
the only reference I can see is to a "JSON text" which is a JSON<br>
representation of a single value. There's nothing describing how<br>
multiple values would be stored in the same file/transmitted in the<br>
same stream. It's not unreasonable to assume "read one object, then<br>
read another" but without an analysis of the grammar, it's not 100%<br>
clear if the grammar supports that (you sort of have to assume that<br>
when you hit "the end of the object" you skip some whitespace then<br>
start on the next - but the spec doesn't say anything like that.<br>
Alternatively, it's just as reasonable to assume that<br>
json.load/json.loads expect to be passed a single "JSON text" as<br>
defined by the spec.<br>
<br>
If the spec was clear on how multiple objects in a single stream<br>
should be handled, then yes the json module should support that. But<br>
without anything explicit in the spec, it's not as obvious. What do<br>
other languages do?<br>
<br>
Paul<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div></div>
</blockquote></div></div>
</div></div><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div></div></div></div>