23 lines
542 B
Python
23 lines
542 B
Python
import json
|
|
from typing import Any, Generic
|
|
|
|
from .core import C, ContextParser, Parser, PrepareParser, R
|
|
|
|
|
|
class _JSONParser(Parser[str, Any]):
|
|
def parse(self, data: str) -> Any:
|
|
return json.loads(data)
|
|
|
|
|
|
JSON_PARSER = _JSONParser()
|
|
|
|
|
|
class JSONParser(PrepareParser[str, Any, R], Generic[R]):
|
|
def prepare(self, data: str) -> Any:
|
|
return JSON_PARSER.parse(data)
|
|
|
|
|
|
class JSONContextParser(ContextParser[C, Any, R], Generic[C, R]):
|
|
def prepare_context(self, data: str) -> Any:
|
|
return JSON_PARSER.parse(data)
|