diff --git a/wechat_cli/output/formatter.py b/wechat_cli/output/formatter.py index 0b1891b..20138d6 100644 --- a/wechat_cli/output/formatter.py +++ b/wechat_cli/output/formatter.py @@ -6,8 +6,14 @@ def output_json(data, file=None): file = file or sys.stdout - json.dump(data, file, ensure_ascii=False, indent=2) - file.write('\n') + # Encode to UTF-8 bytes to avoid encoding issues on Windows + json_str = json.dumps(data, ensure_ascii=False, indent=2) + '\n' + if hasattr(file, 'buffer'): + # Write bytes directly to binary buffer for proper UTF-8 encoding + file.buffer.write(json_str.encode('utf-8')) + else: + # Fallback for file objects without buffer attribute + file.write(json_str) def output_text(text, file=None):