Initial upload: ConfigConvert CLI with full test suite and CI/CD
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-02-04 07:05:20 +00:00
parent 5f0a0b21fd
commit eb95560940

View File

@@ -0,0 +1,32 @@
"""JSON format converter using stdlib json."""
import json
from pathlib import Path
from typing import Any, Dict, Optional
from config_convert.converters.base import Converter
class JSONConverter(Converter):
"""Converter for JSON format."""
@property
def name(self) -> str:
return "json"
def loads(self, data: str) -> Dict[str, Any]:
return json.loads(data)
def dumps(self, data: Dict[str, Any], indent: Optional[int] = None) -> str:
if indent is None:
indent = 2
return json.dumps(data, indent=indent, ensure_ascii=False)
def load(self, file_path: str) -> Dict[str, Any]:
with open(file_path, "r", encoding="utf-8") as f:
return json.load(f)
def dump(self, data: Dict[str, Any], file_path: str, indent: Optional[int] = None) -> None:
Path(file_path).parent.mkdir(parents=True, exist_ok=True)
with open(file_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=indent, ensure_ascii=False)