Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,7 @@ def output_rows(iterator, headers, nl, arrays, json_cols):
data = dict(zip(headers, data))
line = "{firstchar}{serialized}{maybecomma}{lastchar}".format(
firstchar=("[" if first else " ") if not nl else "",
serialized=json.dumps(data, default=json_binary),
serialized=json.dumps(data, default=json_binary, ensure_ascii=False),
maybecomma="," if (not nl and not is_last) else "",
lastchar="]" if (is_last and not nl) else "",
)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,17 @@ def test_query_json(db_path, sql, args, expected):
assert expected == result.output.strip()


def test_query_json_unicode(db_path):
# Regression for #625: JSON output should keep non-ASCII characters
# as themselves, not as \u-escapes.
db = Database(db_path)
with db.conn:
db["t"].insert({"id": 1, "text": "Japanese 日本語"})
result = CliRunner().invoke(cli.cli, [db_path, "select id, text from t"])
assert "日本語" in result.output
assert "\\u65e5" not in result.output


def test_query_json_empty(db_path):
result = CliRunner().invoke(
cli.cli,
Expand Down
Loading