diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 5844dfc0..988f4b99 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -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 "", ) diff --git a/tests/test_cli.py b/tests/test_cli.py index 40b36854..a2ac75eb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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,