PassDict
This class provides a mechanism for tagging dictionary values for JSON serialization. It validates that a value is a dictionary and recursively tags each value within the dictionary while maintaining the original string keys. This ensures that complex nested structures within a dictionary are properly processed for JSON compatibility.
Attributes
| Attribute | Type | Description |
|---|---|---|
| tag | callable | An alias for the to_json method used to process dictionary values for JSON serialization. |
Methods
check()
@classmethod
def check(
value: t.Any
) - > bool
Checks if the provided value is a dictionary instance.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be checked for dictionary type compatibility |
Returns
| Type | Description |
|---|---|
bool | True if the value is a dict, False otherwise |
to_json()
@classmethod
def to_json(
value: t.Any
) - > t.Any
Converts a dictionary into a JSON-serializable format by recursively tagging its values.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The dictionary whose values need to be tagged for JSON serialization |
Returns
| Type | Description |
|---|---|
t.Any | A new dictionary where every value has been processed by the serializer's tagging logic |