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

Vito De Tullio report at bugs.python.org
Mon Nov 29 10:49:18 EST 2021


New submission from Vito De Tullio <vito.detullio at gmail.com>:

It would be useful to let json.tool support empty rows during handling of json lines
generally speaking, this tolerance is already present in parsers like srsly and jsonlines

actual behavior:

# happy scenario
$ echo -e '{"foo":1}\n{"bar":2}' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}
{
    "bar": 2
}
$

# spurious EOL at EOF
$ echo -e '{"foo":1}\n{"bar":2}\n' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}
{
    "bar": 2
}
Expecting value: line 2 column 1 (char 1)
$

# two groups of "rows" in jsonl <- my current usecase
$ echo -e '{"foo":1}\n\n{"bar":2}' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}
Expecting value: line 2 column 1 (char 1)
$


my desired outcome is to preserve the EOLs, so to have something like:

# happy scenario
$ echo -e '{"foo":1}\n{"bar":2}' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}
{
    "bar": 2
}
$

# spurious EOL at EOF
$ echo -e '{"foo":1}\n{"bar":2}\n' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}
{
    "bar": 2
}

$

# two groups of "rows" in jsonl
$ echo -e '{"foo":1}\n\n{"bar":2}' | python3.10 -mjson.tool --json-lines
{
    "foo": 1
}

{
    "bar": 2
}
$

----------
components: Library (Lib)
messages: 407289
nosy: ZeD
priority: normal
severity: normal
status: open
title: extend json.tool --json-lines to ignore empty rows
type: enhancement
versions: Python 3.10

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


More information about the New-bugs-announce mailing list