--nl now ignores blank lines, closes #376

This commit is contained in:
Simon Willison 2022-01-09 20:12:39 -08:00
commit d2a79d200f
2 changed files with 2 additions and 2 deletions

View file

@ -791,7 +791,7 @@ def insert_upsert_implementation(
else:
try:
if nl:
docs = (json.loads(line) for line in decoded)
docs = (json.loads(line) for line in decoded if line.strip())
else:
docs = json.load(decoded)
if isinstance(docs, dict):

View file

@ -165,7 +165,7 @@ def test_insert_newline_delimited(db_path):
result = CliRunner().invoke(
cli.cli,
["insert", db_path, "from_json_nl", "-", "--nl"],
input='{"foo": "bar", "n": 1}\n{"foo": "baz", "n": 2}',
input='{"foo": "bar", "n": 1}\n\n{"foo": "baz", "n": 2}',
)
assert 0 == result.exit_code, result.output
db = Database(db_path)