ValidationError: ValidationError (ProfilingRequest:None) (Invalid
    dictionary key name - keys may not contain "." or "$" characters 1.Invalid
    dictionary key name - keys may not contain "." or "$" characters 2.Invalid
    dictionary key name - keys may not contain "." or "$" characters:
    ['queries'])

def sanitize_dict(d, reverse=False):
    """
    ValidationError: ValidationError (ProfilingRequest:None) (Invalid
    dictionary key name - keys may not contain "." or "$" characters 1.Invalid
    dictionary key name - keys may not contain "." or "$" characters 2.Invalid
    dictionary key name - keys may not contain "." or "$" characters:
    ['queries'])
    """
    data = {}

    if isinstance(d, list):
        list_data = []
        for item in d:
            list_data.append(sanitize_dict(item, reverse=reverse))
        return list_data
    elif not isinstance(d, dict):
        return d

    for k, v in d.items():
        if isinstance(v, dict):
            v = sanitize_dict(v, reverse=reverse)
        elif isinstance(v, list):
            list_data = []
            for item in v:
                list_data.append(item)
            v = sanitize_dict(list_data, reverse=reverse)

        if reverse:
            data[
                k.replace(MONGO_COMMAND_KEY_PERIOD_SIGN_REPLACEMENT, '.').replace(
                    MONGO_COMMAND_KEY_DOLLAR_SIGN_REPLACEMENT, '$'
                )
            ] = v
        else:
            data[
                k.replace('.', MONGO_COMMAND_KEY_PERIOD_SIGN_REPLACEMENT).replace(
                    '$', MONGO_COMMAND_KEY_DOLLAR_SIGN_REPLACEMENT
                )
            ] = v
    return data