Q:

Error recording json file. Open and replace and save

I'm trying to replace the special python characters, but replacing is not working for me.
def enviarwebservice():
    url = "https://server/api/v1/a032ccb8-8c32-4c4e-976a-07f5e9a64e26"       
    files=ls4("c:/validacionFX/","*.json") #*******ruta donde se genera el json*********    
    try:
        r = requests.get(url)
        if 1==1:
            for archivo in files:        
                if os.path.isfile(archivo):      
                    with io.open(archivo,'r',encoding='utf8')as file:
                        cadenaId=(os.path.basename(archivo)).split('-') #--es una tipo lista.   
                        print("Antes de leer")   
                        file_data=file.read().replace('\\"', '\"').replace('\\n','\n').replace('\\',' ')
                        with io.open(archivo,'w',encoding='utf8')as f:
                            f.write(file_data)
                            json_data=json.load(f)        
                            payload=json.dumps(json_data,indent=4)

A:

If you want to read what you just wrote, you need to open the file in w+ mode, not w mode. You also have to rewind the file, otherwise you start reading from the end of what you wrote, and there's nothing there.
                        with io.open(archivo,'w+',encoding='utf8')as f:
                            f.write(file_data)
                            f.seek(0)
                            json_data=json.load(f)        

But there's no reason to read it back from the file. You already have the JSON in file_data, you can load that.
Also, you should close the first file handle before writing back out to the same file. Take the second with block outside of the first one.
            for archivo in files:        
                if os.path.isfile(archivo):      
                    with io.open(archivo,'r',encoding='utf8')as file:
                        cadenaId=(os.path.basename(archivo)).split('-') #--es una tipo lista.   
                        print("Antes de leer")   
                        file_data=file.read().replace('\\"', '\"').replace('\\n','\n').replace('\\',' ')
                    with io.open(archivo,'w',encoding='utf8')as f:
                        f.write(file_data)
                    json_data=json.loads(file_data)        

However, I think what you're doing may be misguided in the first place. You're replacing escaped characters with non-escaped characters, but escaping is necessary when special characters are embedded in JSON.

