From d36ad17a976e98c79ece0f439d39ffdbcd5a2758 Mon Sep 17 00:00:00 2001 From: marupakalaharsith20-beep <242739440+marupakalaharsith20-beep@users.noreply.github.com> Date: Sun, 25 Oct 2026 12:50:46 +0530 Subject: [PATCH] fix(jsonfmt): preserve non-ASCII characters in format_json (closes #8) --- fixit/jsonfmt.py | 2 +- tests/test_jsonfmt.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fixit/jsonfmt.py b/fixit/jsonfmt.py index 89ba00f..e427e00 100644 --- a/fixit/jsonfmt.py +++ b/fixit/jsonfmt.py @@ -11,6 +11,6 @@ def format_json(raw: str, indent: int = 2) -> str: """ try: data = json.loads(raw) - return json.dumps(data, indent=indent) + return json.dumps(data, indent=indent, ensure_ascii=False) except json.JSONDecodeError: raise ValueError("Invalid JSON") diff --git a/tests/test_jsonfmt.py b/tests/test_jsonfmt.py index dbdb514..24a5a25 100644 --- a/tests/test_jsonfmt.py +++ b/tests/test_jsonfmt.py @@ -10,3 +10,8 @@ def test_format_json(): def test_invalid_json_friendly_error(): with pytest.raises(ValueError, match="Invalid JSON"): format_json("{not json") + + +def test_format_json_preserves_unicode(): + assert format_json('{"name": "café"}') == '{\n "name": "café"\n}' +