[issue45929] extend json.tool --json-lines to ignore empty rows

Łukasz Langa report at bugs.python.org
Fri Dec 10 18:59:03 EST 2021


Łukasz Langa <lukasz at langa.pl> added the comment:

I agree with Serhiy that in general the fact that json.tool crashes here is useful: similarly to an exception in Python code, it can inform the user that some data they feed to json.tool is invalid.

At the same time, I find it a bit obnoxious that the current implementation doesn't allow for the *final character* of the input to be a newline (or "characters" in case of \r\n... but it should still only ignore *a single effective newline*).

I mean, if the user starts spewing newlines in the middle of the file... that might easily be an error. If the file ends with 5 empty lines, that might easily be an error. But, if the file really is:

{'line': 1, 'data': ...}\n
{'line': 2, 'data': ...}\n
{'line': 3, 'data': ...}\n

I think that should be pragmatically accepted by json.tool, especially since many text editors now add newline characters at file ends.

----------
nosy: +lukasz.langa

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45929>
_______________________________________


More information about the Python-bugs-list mailing list