import json


def del_from_txt_bad_json_symbols(txt):

    log = ''
    error = True
    while error and len(txt) > 0:
        try:
            json.loads(txt)
            error = None
        except json.JSONDecodeError as e:
            msg = '- длина контента = {2} - {1} - удален символ {0}'.format(
                txt[e.pos],
                str(e),
                str(len(txt)-1)
            )
            log = '{0}<br>{1}'.format(log, msg)
            print(msg)
            txt = txt[:e.pos] + txt[e.pos+1:]
            error = e

    # import re
    # r_str =  r'[{\[]([,:{}\[\]0-9.\-+A-zr-u \n\r\t]|".*:?")+[}\]]'
    # pattern = re.compile(r_str)
    # txt = re.sub(r_str, '',txt)
    # res = pattern.search(txt)
    # if res:
    #     txt = res.string

    return txt, log