multiple JSON documents in one file, change proposal

Marko Rauhamaa marko at pacujo.net
Fri Nov 30 17:40:06 EST 2018


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.

> 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