Home / Class/ JSONTag Class — flask Architecture

JSONTag Class — flask Architecture

Architecture documentation for the JSONTag class in tag.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  a0222544_1c8a_9b62_d419_e9d66bd3544a["JSONTag"]
  5e2eed77_f23f_513d_2d00_d39ce63b14ab["tag.py"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|defined in| 5e2eed77_f23f_513d_2d00_d39ce63b14ab
  1f2a6811_d0fe_8fe1_950b_34b52056c7a6["__init__()"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|method| 1f2a6811_d0fe_8fe1_950b_34b52056c7a6
  27bf4ac3_994f_6adb_5352_845ce1b7d3f8["check()"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|method| 27bf4ac3_994f_6adb_5352_845ce1b7d3f8
  1345c634_4b56_f84b_d547_757aafd127a4["to_json()"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|method| 1345c634_4b56_f84b_d547_757aafd127a4
  aa526dad_8105_ef0f_0744_9a4830e84cf2["to_python()"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|method| aa526dad_8105_ef0f_0744_9a4830e84cf2
  cc664eee_e322_7454_0ffe_63c77d52dae1["tag()"]
  a0222544_1c8a_9b62_d419_e9d66bd3544a -->|method| cc664eee_e322_7454_0ffe_63c77d52dae1

Relationship Graph

Source Code

src/flask/json/tag.py lines 60–90

class JSONTag:
    """Base class for defining type tags for :class:`TaggedJSONSerializer`."""

    __slots__ = ("serializer",)

    #: The tag to mark the serialized object with. If empty, this tag is
    #: only used as an intermediate step during tagging.
    key: str = ""

    def __init__(self, serializer: TaggedJSONSerializer) -> None:
        """Create a tagger for the given serializer."""
        self.serializer = serializer

    def check(self, value: t.Any) -> bool:
        """Check if the given value should be tagged by this tag."""
        raise NotImplementedError

    def to_json(self, value: t.Any) -> t.Any:
        """Convert the Python object to an object that is a valid JSON type.
        The tag will be added later."""
        raise NotImplementedError

    def to_python(self, value: t.Any) -> t.Any:
        """Convert the JSON representation back to the correct type. The tag
        will already be removed."""
        raise NotImplementedError

    def tag(self, value: t.Any) -> dict[str, t.Any]:
        """Convert the value to a valid JSON type and add the tag structure
        around it."""
        return {self.key: self.to_json(value)}

Domain

Frequently Asked Questions

What is the JSONTag class?
JSONTag is a class in the flask codebase, defined in src/flask/json/tag.py.
Where is JSONTag defined?
JSONTag is defined in src/flask/json/tag.py at line 60.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free