mongoengine_goodjson package¶
Subpackages¶
Submodules¶
mongoengine_goodjson.decoder module¶
Human-readable JSON decoder for MongoEngine.
-
class
mongoengine_goodjson.decoder.
ObjectHook
(cls)[source]¶ Bases:
object
Human readable JSON decoder for MongoEngine.
Note the instance of this object is callable object, so you can create the instance of this class, then, put object_hook kwargs.
-
mongoengine_goodjson.decoder.
generate_object_hook
¶
mongoengine_goodjson.document module¶
Documents implementing human-readable JSON serializer.
-
class
mongoengine_goodjson.document.
Document
(*args, **values)[source]¶ Bases:
mongoengine_goodjson.document.Helper
,mongoengine.document.Document
Document implementing human-readable JSON serializer.
-
class
mongoengine_goodjson.document.
EmbeddedDocument
(*args, **kwargs)[source]¶ Bases:
mongoengine_goodjson.document.Helper
,mongoengine.document.EmbeddedDocument
EmbeddedDocument implementing human-readable JSON serializer.
-
class
mongoengine_goodjson.document.
Helper
[source]¶ Bases:
object
Helper class to serialize / deserialize JSON document.
-
classmethod
from_json
(json_str, created=False, *args, **kwargs)[source]¶ Decode from human-readable json.
- Parameters
json_str – JSON string that should be passed to the serialized
created – a parameter that is passed to cls._from_son.
**kwargs (*args,) –
Any additional arguments that is passed to json.loads.
-
to_json
(*args, **kwargs)[source]¶ Encode to human-readable json.
- Parameters
use_db_field – use_db_field that is passed to to_mongo.
follow_reference – set True to follow reference field.
max_depth – maximum recursion depth. If this value is set to None, the reference is followed until it is end. Setting 0 is the same meaning of follow_reference=0. By default, the value is 3.
current_depth – This is used internally to identify current recursion depth. Therefore, you should leave this value as-is. By default, the value is 0.
**kwargs (*args,) –
Any arguments, and keyword arguments to tell json.dumps.
-
classmethod
mongoengine_goodjson.encoder module¶
Encoder module.
mongoengine_goodjson.queryset module¶
Queryset encoder.
mongoengine_goodjson.utils module¶
Utility functions.
-
mongoengine_goodjson.utils.
id_first
(dct)[source]¶ Return dict that comes id first.
Note that this func returns dct as it is if “id” is not found in dct.
-
mongoengine_goodjson.utils.
method_dispatch
(func)[source]¶ Dispatch class instance method with functools.singledispatch.
Module contents¶
JSON serializer/deserializer for humans and MongoEngine.
-
class
mongoengine_goodjson.
GoodJSONEncoder
(epoch_mode=False, *args, **kwargs)[source]¶ Bases:
json.encoder.JSONEncoder
JSON Encoder for human and MongoEngine.
-
mongoengine_goodjson.
generate_object_hook
¶
-
class
mongoengine_goodjson.
Document
(*args, **values)[source]¶ Bases:
mongoengine_goodjson.document.Helper
,mongoengine.document.Document
Document implementing human-readable JSON serializer.
-
class
mongoengine_goodjson.
EmbeddedDocument
(*args, **kwargs)[source]¶ Bases:
mongoengine_goodjson.document.Helper
,mongoengine.document.EmbeddedDocument
EmbeddedDocument implementing human-readable JSON serializer.
-
class
mongoengine_goodjson.
QuerySet
(document, collection)[source]¶ Bases:
mongoengine.queryset.queryset.QuerySet
QuerySet that supports human-readable json.
-
class
mongoengine_goodjson.
FollowReferenceField
(*args, **kwargs)[source]¶ Bases:
mongoengine.fields.ReferenceField
Follow Reference Field.
This field can be treated as a field like ReferenceField, but generates the JSON/dict of the referenced document like embedded document.
Note
This field doesn’t check recursion level. Therefore, please be careful for self-referenced document.