def _parse_canonical_oid(doc):
    """Decode a JSON ObjectId to bson.objectid.ObjectId."""
    if len(doc) != 1:
        raise TypeError('Bad $oid, extra field(s): %s' % (doc,))
    return ObjectId(doc['$oid'])
Decode a JSON ObjectId to bson.objectid.ObjectId.
stackoverflow/venv/lib/python3.6/site-packages/bson/json_util.py