cli: output JSON without escaping non-ASCII characters

Closes #625.

json.dumps defaults to ensure_ascii=True, so output_rows emitted
'\u65e5\u672c\u8a9e' instead of '日本語' for Japanese.
The CSV path already shows the characters verbatim - the JSON path
should too. Pass ensure_ascii=False so the bytes match what the CSV
output (and the database itself) holds.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This commit is contained in:
Charlie Tonneslan 2026-05-18 11:08:36 -04:00
commit 4bfb53aae3
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View file

@ -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 "",
)