jsanitize

emmet.core.utils.jsanitize(obj, strict=False, allow_bson=False)

This method cleans an input json-like object, either a list or a dict or some sequence, nested or otherwise, by converting all non-string dictionary keys (such as int and float) to strings, and also recursively encodes all objects using Monty’s as_dict() protocol. Args:

obj: input json-like object. strict (bool): This parameters sets the behavior when jsanitize

encounters an object it does not understand. If strict is True, jsanitize will try to get the as_dict() attribute of the object. If no such attribute is found, an attribute error will be thrown. If strict is False, jsanitize will simply call str(object) to convert the object to a string representation.

allow_bson (bool): This parameters sets the behavior when jsanitize

encounters an bson supported type such as objectid and datetime. If True, such bson types will be ignored, allowing for proper insertion into MongoDb databases.

Returns:

Sanitized dict that can be json serialized.