Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!