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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM