Skip to content

application_json

Strategy class for application/json.

JSONConfig

Bases: AttrDict

JSON parse-specific Configuration Data Model.

Source code in oteapi/strategies/parse/application_json.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class JSONConfig(AttrDict):
    """JSON parse-specific Configuration Data Model."""

    downloadUrl: Optional[HostlessAnyUrl] = Field(
        None, description="The HTTP(S) URL, which will be downloaded."
    )
    mediaType: Literal["application/json"] = Field(
        "application/json",
        description=("The media type"),
    )
    datacache_config: Optional[DataCacheConfig] = Field(
        None,
        description=(
            "Configurations for the data cache for storing the downloaded file "
            "content."
        ),
    )

datacache_config: Optional[DataCacheConfig] = Field(None, description='Configurations for the data cache for storing the downloaded file content.') class-attribute instance-attribute

downloadUrl: Optional[HostlessAnyUrl] = Field(None, description='The HTTP(S) URL, which will be downloaded.') class-attribute instance-attribute

mediaType: Literal['application/json'] = Field('application/json', description='The media type') class-attribute instance-attribute

JSONDataParseStrategy

Parse strategy for JSON.

Registers strategies:

  • ("parserType", "parser/json")
Source code in oteapi/strategies/parse/application_json.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@dataclass
class JSONDataParseStrategy:
    """Parse strategy for JSON.

    **Registers strategies**:

    - `("parserType", "parser/json")`

    """

    parse_config: JSONParserConfig

    def initialize(self) -> AttrDict:
        """Initialize."""
        return AttrDict()

    def get(self) -> JSONParseContent:
        """Parse json."""
        downloader = create_strategy(
            "download", self.parse_config.configuration.model_dump()
        )
        output = downloader.get()
        cache = DataCache(self.parse_config.configuration.datacache_config)
        content = cache.get(output["key"])

        if isinstance(content, dict):
            return JSONParseContent(content=content)
        return JSONParseContent(content=json.loads(content))

parse_config: JSONParserConfig instance-attribute

get()

Parse json.

Source code in oteapi/strategies/parse/application_json.py
75
76
77
78
79
80
81
82
83
84
85
86
def get(self) -> JSONParseContent:
    """Parse json."""
    downloader = create_strategy(
        "download", self.parse_config.configuration.model_dump()
    )
    output = downloader.get()
    cache = DataCache(self.parse_config.configuration.datacache_config)
    content = cache.get(output["key"])

    if isinstance(content, dict):
        return JSONParseContent(content=content)
    return JSONParseContent(content=json.loads(content))

initialize()

Initialize.

Source code in oteapi/strategies/parse/application_json.py
71
72
73
def initialize(self) -> AttrDict:
    """Initialize."""
    return AttrDict()

JSONParseContent

Bases: AttrDict

Class for returning values from JSON Parse.

Source code in oteapi/strategies/parse/application_json.py
53
54
55
56
class JSONParseContent(AttrDict):
    """Class for returning values from JSON Parse."""

    content: dict = Field(..., description="Content of the JSON document.")

content: dict = Field(..., description='Content of the JSON document.') class-attribute instance-attribute

JSONParserConfig

Bases: ParserConfig

JSON parse strategy filter config.

Source code in oteapi/strategies/parse/application_json.py
41
42
43
44
45
46
47
48
49
50
class JSONParserConfig(ParserConfig):
    """JSON parse strategy filter config."""

    parserType: Literal["parser/json"] = Field(
        "parser/json",
        description=ParserConfig.model_fields["parserType"].description,
    )
    configuration: JSONConfig = Field(
        ..., description="JSON parse strategy-specific configuration."
    )

configuration: JSONConfig = Field(..., description='JSON parse strategy-specific configuration.') class-attribute instance-attribute

parserType: Literal['parser/json'] = Field('parser/json', description=ParserConfig.model_fields['parserType'].description) class-attribute instance-attribute