multiple JSON documents in one file, change proposal

Thomas Jollans tjol at tjol.eu
Fri Nov 30 17:54:28 EST 2018


On 30/11/2018 23:40, Marko Rauhamaa 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.

FWIW, YAML supports multiple documents in one stream (separated by ---)

If you just want multiple JSON objects in a file (without any streaming
needs), you can just use a JSON array...
> 
>> I also recommend the following article to those not aware of how badly
>> designed JSON is: http://seriot.ch/parsing_json.php
> 
> JSON is not ideal, but compared with XML, it's a godsend.
> 
> What would be ideal? I think S-expressions would come close, but people
> can mess up even them: <URL: https://www.ietf.org/rfc/rfc2693.txt>.
> 
> 
> Marko
> 




More information about the Python-list mailing list