Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Correcting strings inside json file

I have a json file in that title entity is there. I parse the title, it gives error because of '\' character in the title.

for(int i = 0; i < stringJSON.length() - 1; i++){
                if(stringJSON.charAt(i) == character && !(stringJSON.charAt(i+1) == character)){
                    rawJSON = new StringBuilder(stringJSON).insert(i+1, '\\').toString();
                    i = i + 2;
                   System.out.println("found at " + i);
                }

Input json file is as below-

{ "class":
        {
            "number": 2,
            "student": 
            {
            "title": "\\The first day \b of my life",
            "age": 1
            },
            "student": 
            {
            "title": "\\A corner in the \A home",
            "age": 2
            }
        }
    }  

The solution above have lot of issues, like "\\" is a valid character, '\"' is a valid character.

Can somebody help me to find out any java package or API which helps to auto correct this kind of error?

In the second record of student, you can see a single slash. That makes json invalid.

My question is how to correct this json? I can either remove it or append one more slash to make it valid json string.

The string is combination of escape characters "\\", and control character '\'.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This answers what you are asking:

You can see there how the \ is a "control" character. If you want a literal backslash within your JSON, you'll need to escape it: "\\" is a valid JSON string, for example.

Source: JSON Valid Chars

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda