MongoDB ObjectId类型 序列化问题

MongoDB ObjectId类型 序列化问题

data = mongo的Bson数据

import json
from bson import json_util
data = json.loads(
    json.dumps(
        data,
        sort_keys=False,
        indent=4,
        default=json_util.default)
    )

JSON (JavaScript Object Notation)

http://json.org is a subset of
JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
interchange format.

Pretty printing::

    >>> import json
    >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4))
    {
        "4": 5,
        "6": 7
    }

json.dumps()

If ``indent`` is a non-negative integer, then JSON array elements and
object members will be pretty-printed with that indent level. An indent
level of 0 will only insert newlines. ``None`` is the most compact
representation.

``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.

If *sort_keys* is true (default: ``False``), then the output of
dictionaries will be sorted by key.
posted @ 2020-08-21 20:17  justblue  阅读(704)  评论(0编辑  收藏  举报