Serializers¤
Main API¤
See the as_json() and from_json() methods of objects.
Advanced API¤
JSONEncoder ¤
Bases: JSONEncoder
flowchart TD
griffe.JSONEncoder[JSONEncoder]
click griffe.JSONEncoder href "" "griffe.JSONEncoder"
JSON encoder.
JSON encoders can be used directly, or through the json.dump or json.dumps methods.
Examples:
>>> from griffe import JSONEncoder
>>> JSONEncoder(full=True).encode(..., **kwargs)
>>> import json
>>> from griffe import JSONEncoder
>>> json.dumps(..., cls=JSONEncoder, full=True, **kwargs)
Parameters:
-
(*args¤Any, default:()) –See
json.JSONEncoder. -
(full¤bool, default:False) –Whether to dump full data or base data. If you plan to reload the data in Python memory using the
json_decoder, you don't need the full data as it can be inferred again using the base data. If you want to feed a non-Python tool instead, dump the full data. -
(**kwargs¤Any, default:{}) –See
json.JSONEncoder.
- Guide User guide Manipulating APIs Serializing APIs Python API
- Reference
griffe Serializers
Methods:
-
default–Return a serializable representation of the given object.
Attributes:
Source code in packages/griffelib/src/griffe/_internal/encoders.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
default ¤
Return a serializable representation of the given object.
Parameters:
Returns:
-
Any–A serializable representation.
Source code in packages/griffelib/src/griffe/_internal/encoders.py
93 94 95 96 97 98 99 100 101 102 103 104 105 | |
json_decoder ¤
json_decoder(
obj_dict: dict[str, Any],
) -> (
dict[str, Any]
| Object
| Alias
| Parameter
| TypeParameter
| str
| Expr
)
Decode dictionaries as data classes.
The json.loads method walks the tree from bottom to top.
Examples:
>>> import json
>>> from griffe import json_decoder
>>> json.loads(..., object_hook=json_decoder)
Parameters:
Returns:
-
dict[str, Any] | Object | Alias | Parameter | TypeParameter | str | Expr–An instance of a data class.
- Guide User guide Manipulating APIs Serializing APIs Python API
- Reference
Source code in packages/griffelib/src/griffe/_internal/encoders.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |