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