Skip to main content

TagDict

Tag for 1-item dicts whose only key matches a registered tag.

Attributes

AttributeTypeDescription
keystring = " di"The unique identifier used by the serializer to represent a 1-item dictionary tag in JSON output.

Methods


check()

@classmethod
def check(
value: t.Any
) - > bool

Determines if a value is a single-item dictionary whose key corresponds to a registered tag in the serializer.

Parameters

NameTypeDescription
valuet.AnyThe object to evaluate for compatibility with this tag type

Returns

TypeDescription
boolTrue if the value is a dictionary of length one with a valid tag key, False otherwise

to_json()

@classmethod
def to_json(
value: t.Any
) - > t.Any

Converts a single-item dictionary into its JSON-safe representation by appending a double-underscore suffix to the key and recursively tagging the value.

Parameters

NameTypeDescription
valuet.AnyThe single-item dictionary to be serialized

Returns

TypeDescription
t.AnyA dictionary with the suffixed key and the serialized version of the original value

to_python()

@classmethod
def to_python(
value: t.Any
) - > t.Any

Restores a JSON-serialized dictionary back to its Python form by removing the double-underscore suffix from the dictionary key.

Parameters

NameTypeDescription
valuet.AnyThe serialized dictionary containing a suffixed key

Returns

TypeDescription
t.AnyA dictionary containing the original key name and the associated value