While analizing some code i am using
            <script>console.log("Cias", {{ dia.cias| json_encode| raw}});</script>
            <script>console.log("Dia",{{ key| json_encode| raw}});</script>
            <script>console.log("Datos",{{ dia| json_encode| raw}});</script>
            <script>console.log("CodigoEstadoAusencia",{{ dump(dia.codEstadoAusencia)| json_encode| raw}});</script>
            <script>console.log("TipoTit",{{ dump(tipoTit)| json_encode| raw}});</script>
            <script>console.log("-------------------------------------------------------------------------");</script>
And i recieve 2 diferent outputs. This first one is incomplete and is what i want to fix
Cias 1601140113N 
Dia 22
Datos  // (empty) I also get "undefined" if i stringify the output for thiss
CodigoEstadoAusencia string(2) "30"
TipoTit string(1) "T"
-------------------------------------------------------------------------
But i also recieve correct output like the following:
Cias 1601140113N 
Dia 21
Datos
 cias: "1601140113N"
 dia: "21"
    codEstadoAusencia: "30"
    descripcionEstadoAusencia: "CONTRATADO"
    estadoSustitucion: {…}
      pedidoSustituto: "S"
      sustitutoJano: {…}
        CONTRATADO: "S"
        DOBLAJE: "N"
        FFIN: null
        FINI: "2019-05-20"
        ID: "213095"
        NIF: "         "
        NOMBRE: "John Doe"
        SOLICITUD: "390804"
        TELEFONO: "699999999           "
      dia: "2019-04-21"
      idSolicitud: "390804"
    idAlta: "128096"
    movianterior: "445223"
    situacionAdministrativa: "T"
    sustitutoSaint: null
    sustitutos: "S"
    tipoAusencia: "390804"
    turno: "TARDE"  
CodigoEstadoAusencia string(2) "30"
TipoTit string(1) "T"
-------------------------------------------------------------------------   
As you can see in the "bad" output i can access the attributes from "dia" like dia.codEstadoAusencia where i got "30", BUT it seems unable to output the full object and no error is displayed. I've already tried the combinations of using the pipes with raw ,with/without json_encode, using json_encode(constant('JSON_PRETTY_PRINT')) , without dump, alerting the content, changing the order of dumps...
I only got the conclusion that in some cases it doesnt create the object correctly but cant figure out where is the problem. ¿Any ideas?
Edit: After the suggestion from duplicate mark i tried filtering with | convert_encoding('UTF-8', 'ISO-8859-1) and some other common charsets but the encoding doesnt seem the problem or the filter is not working for me
Edit2: Added some missing data from the response for clarification
