multiple JSON documents in one file, change proposal

Grant Edwards grant.b.edwards at gmail.com
Sat Dec 1 15:17:49 EST 2018


On 2018-11-30, Marko Rauhamaa <marko at pacujo.net> wrote:
> Paul Rubin <no.email at nospam.invalid>:
>> Maybe someone can convince me I'm misusing JSON but I often want to
>> write out a file containing multiple records, and it's convenient to
>> use JSON to represent the record data.
>>
>> The obvious way to read a JSON doc from a file is with "json.load(f)"
>> where f is a file handle. Unfortunately, this throws an exception
>
> I have this "multi-JSON" need quite often. In particular, I exchange
> JSON-encoded messages over byte stream connections. There are many ways
> of doing it. Having rejected different options (<URL:
> https://en.wikipedia.org/wiki/JSON_streaming>), I settled with
> terminating each JSON value with an ASCII NUL character, which is
> illegal in JSON proper.

This is what "archive" file formats are for.  Just use tar, zip, ar,
cpio, or some other file format designed to store multiple "files" of
arbitrary data -- there are plenty of "standard" formats to choose
from and plenty of libraries to deal with them.

-- 
Grant



More information about the Python-list mailing list