def METHOD_NAME(obj):
    """Ensures that all strings are valid UTF-8 encoded, which is
    required by MongoDB to be able to store the JSON documents.
    @param obj: analysis results dictionary.
    """
    if not obj:
        return
    items = []
    if isinstance(obj, dict):
        items = obj.items()
    elif isinstance(obj, list):
        items = enumerate(obj)
    for k, v in items:
        # This type check is intentionally not done using isinstance(),
        # because bson.binary.Binary *is* a subclass of bytes/str, and
        # we do not want to convert that.
        if isinstance(v, str):
            try:
                v.encode()
            except UnicodeEncodeError:
                obj[k] = "".join(str(ord(_)) for _ in v).encode()
        else:
            METHOD_NAME(v)