diff --git a/src/converters/json_converter.py b/src/converters/json_converter.py new file mode 100644 index 0000000..6257304 --- /dev/null +++ b/src/converters/json_converter.py @@ -0,0 +1,39 @@ +"""JSON converter module.""" + +import json +from typing import Any + +from .base import BaseConverter + + +class JSONConverter(BaseConverter): + """Converter for JSON format.""" + + format_name = 'json' + extensions = ('.json',) + + def loads(self, content: str) -> Any: + """Parse JSON string to Python object. + + Args: + content: JSON string content + + Returns: + Parsed Python object + + Raises: + json.JSONDecodeError: If content is not valid JSON + """ + return json.loads(content) + + def dumps(self, data: Any, indent: int = 2) -> str: + """Serialize Python object to JSON string. + + Args: + data: Python object to serialize + indent: Number of spaces for indentation + + Returns: + JSON string representation + """ + return json.dumps(data, indent=indent, ensure_ascii=False)