MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / write_json_file

Function write_json_file

src/core/utils.py:358–380  ·  view source on GitHub ↗

写入 JSON 文件 Args: filepath: 文件路径 data: 要写入的数据 indent: 缩进空格数 Returns: 是否成功

(filepath: str, data: Dict[str, Any], indent: int = 2)

Source from the content-addressed store, hash-verified

356
357
358def write_json_file(filepath: str, data: Dict[str, Any], indent: int = 2) -> bool:
359 """
360 写入 JSON 文件
361
362 Args:
363 filepath: 文件路径
364 data: 要写入的数据
365 indent: 缩进空格数
366
367 Returns:
368 是否成功
369 """
370 try:
371 # 确保目录存在
372 os.makedirs(os.path.dirname(filepath), exist_ok=True)
373
374 with open(filepath, 'w', encoding='utf-8') as f:
375 json.dump(data, f, ensure_ascii=False, indent=indent)
376
377 return True
378 except (IOError, TypeError) as e:
379 logging.getLogger(__name__).error(f"写入 JSON 文件失败: {filepath} - {e}")
380 return False
381
382
383def get_project_root() -> Path:

Callers

nothing calls this directly

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected