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
6 changes: 3 additions & 3 deletions parallel_web_tools/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ def write_json_output(data: dict[str, Any], output_file: str | None, output_json
output_json: If True, print JSON to stdout.
"""
if output_file:
with open(output_file, "w") as f:
json.dump(data, f, indent=2)
with open(output_file, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
console.print(f"[dim]Results saved to {output_file}[/dim]\n")

if output_json:
print(json.dumps(data, indent=2))
print(json.dumps(data, indent=2, ensure_ascii=False))


def parse_columns(columns_json: str | None) -> list[dict[str, str]] | None:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,15 @@ def test_write_to_stdout(self, capsys):
output = json.loads(capsys.readouterr().out)
assert output == data

def test_preserves_non_ascii_characters(self, tmp_path, capsys):
output_file = tmp_path / "output.json"
data = {"title": "中文搜索"}

write_json_output(data, str(output_file), output_json=True)

assert "中文搜索" in output_file.read_text(encoding="utf-8")
assert "中文搜索" in capsys.readouterr().out

def test_write_to_both(self, tmp_path, capsys):
"""Should write to file AND stdout when both specified."""
output_file = tmp_path / "output.json"
Expand Down