Source code for registrar.route.json

import json
from typing import List, Optional

from ..abc import Route
from ..config import RouteConfig, SourceConfig
from ..source import Source, get_source


[docs]class JSONRoute(Route[dict]): """Route handler that handles raw JSON objects""" def __init__( self, config: RouteConfig, href_field: Optional[str] = None ): super().__init__(config) self.href_field = href_field
[docs] def parse(self, raw: str) -> dict: return json.loads(raw)
[docs] def get_source( self, source_cfgs: List[SourceConfig], item: dict ) -> Optional[Source]: if self.href_field: path = item[self.href_field] return get_source(source_cfgs, [path]) else: return None