I have tried using same json file document mentioned by you, the only change that i did is iterating the Json String. Please see the below code.

It works.

   try{

        List<Document> docList = [Select Id,Type,body, bodyLength, ContentType, Url from Document WHERE ID='01528000003FqHJAA0'];

        String jsonStr='';
        if(docList.size()>0)
        {
            Blob b =  docList[0].body;
            jsonStr = b.toString();  
        }

        Map<String,Object> mapObj = (Map<String,Object>)JSON.deserializeUntyped(jsonStr);
        for (String key : mapObj.keySet()){
            System.debug('KEY :' + key);
            System.debug('Value :' + mapObj.get(key));
        }

    }catch(Exception exe){
        System.debug('EEROR OCCURED : '+exe.getMessage());
    }
Answer from Sharan Desai on Stack Exchange
🌐
TutorialsPoint
tutorialspoint.com › json_simple › json_simple_escape_characters.htm
JSON.simple - Escaping Special Characters
import org.json.simple.JSONObject; public class JsonDemo { public static void main(String[] args) { JSONObject jsonObject = new JSONObject(); String text = "Text with special character /\"\'\b\f\t\r\n."; System.out.println(text); System.out.println("After escaping."); text = jsonObject.escape(text); System.out.println(text); } }
Discussions

java - How to escape Special Characters in JSON - Stack Overflow
We have a form which has a long paragraph for a scienctific application that contains characters like symbol beta(ß-arrestin) etc. We have a JSON service running on Mule that takes the data and per... More on stackoverflow.com
🌐 stackoverflow.com
Deal with strings with many special characters like (",',:,;,{,]) etc while doing JSON.parse
Why would you JSON.parse a string that is not a valid json string? Where did you get this string from? :D More on reddit.com
🌐 r/javascript
8
3
July 4, 2017
Java escape JSON String? - Stack Overflow
-1 Message contains escape character in the message sent to MQ and cause exception when converting to JSON · 1 Parsing unquoted JSON keys using org.json.simple in Java More on stackoverflow.com
🌐 stackoverflow.com
java - Deserializing JSON with special characters into a string - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
🌐
Sportakkoordoldenzaal
sportakkoordoldenzaal.nl › building-structure-zaw65 › how-to-parse-json-string-containing-special-characters-in-java.html
How to parse json string containing special characters in java
If the object containing this string was decoded from a string, then this method In the case of an object, you can include all types of values (see the JSON data Conversion of a string containing special characters: $p:=JSON Parse($s) 22 Aug 2018 Parse and render the special characters in rest ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 62274011 › deserializing-json-with-special-characters-into-a-string
java - Deserializing JSON with special characters into a string - Stack Overflow
Config.java private static final ObjectMapper OBJECT_MAPPER; static { OBJECT_MAPPER = new ObjectMapper(); OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); OBJECT_MAPPER.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); OBJECT_MAPPER.enableDefaultTyping(); } @JsonCreator public Config( @JsonProperty(value = "foo", required = true) final String version, @JsonProperty(value = "bar") final List<String> barTypes) { // rest of constructor } public static Config fromJson(final Reader reader) throws IOException { return OBJECT_MAPPER.readValue(reader, Config.class); } ... Failed to parse type 'abc/bcf<object@twenty>.xyz' (remaining: '<object@twenty>.xyz'): Cannot locate class 'abc/bcf', problem: abc/bcf"
🌐
Blogger
javarevisited.blogspot.com › 2017 › 06 › how-to-escape-json-string-in-java-eclipse-IDE.html
How to Escape JSON String in Java- Eclipse IDE Tips and Example
Here are the exact steps to enable this String escape setting into Eclipse IDE: 1. Open Eclipse IDE 2. Go to Windows --> Preferences --> Java --> Editor --> Typing 3) Check the checkbox "Escape text when pasting into a String literal" on section "In String literals.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › parse-json-array-result-with-escape-characters › m-p › 2459285
Solved: Parse JSON array result with escape characters - ServiceNow Community
February 1, 2023 - Using JSON.parse(cases.data[i].recordInfo).fieldname did the trick! ... (Article3_ TM) Few specific special character getting distorted while exported as Excel/csv in Developer forum Sunday
🌐
CodingTechRoom
codingtechroom.com › question › -deserializing-json-special-characters-string
How to Properly Deserialize JSON with Special Characters into a String - CodingTechRoom
Ensure your JSON string is properly formatted, using double quotes and escaping any necessary characters (e.g., newline, tab, etc.). Utilize JSON.parse() in JavaScript or equivalent methods in other languages to convert JSON strings into usable objects, ensuring special characters are preserved.
Top answer
1 of 1
3

Classes

Here are two classes that solve initial problem with broken json:

public class FixedJson {

    private final String target;

    private final Pattern pattern;

    public FixedJson(String target) {
        this(
            target,
            Pattern.compile("\"(.+?)\"[^\\w\"]")
        );
    }

    public FixedJson(String target, Pattern pattern) {
        this.target = target;
        this.pattern = pattern;
    }

    public String value() {
        return this.pattern.matcher(this.target).replaceAll(
            matchResult -> {
                StringBuilder sb = new StringBuilder();
                sb.append(
                    matchResult.group(),
                    0,
                    matchResult.start(1) - matchResult.start(0)
                );
                sb.append(
                    new Escaped(
                        new Escaped(matchResult.group(1)).value()
                    ).value()
                );
                sb.append(
                    matchResult.group().substring(
                        matchResult.group().length() - (matchResult.end(0) - matchResult.end(1))
                    )
                );
                return sb.toString();
            }
        );
    }
}
public class Escaped {

    private final String target;

    private final Pattern pattern;

    public Escaped(String target) {
        this(
            target,
            Pattern.compile("[\\\\\"]")
        );
    }

    public Escaped(String target, Pattern pattern) {
        this.target = target;
        this.pattern = pattern;
    }

    public String value() {
        return this.pattern
            .matcher(this.target)
            .replaceAll("\\\\$0");
    }
}

Unit-tests

And I've written unit-tests to prove the correctness:

import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class FixedJsonTest {

    @Test
    public void normalValue() {
        assertEquals(
            "{\"notes_text\": \"someString\"}",
            new FixedJson("{\"notes_text\": \"someString\"}").value()
        );
    }

    @Test
    public void valueWithOneDoubleQuotes() {
        assertEquals(
            "{\"notes_text\": \"\\\"\"}",
            new FixedJson("{\"notes_text\": \"\"\"}").value()
        );
    }

    @Test
    public void valueWithOneDoubleQuotesAndAnotherValue() {
        assertEquals(
            "{\"notes_text\": \"\\\"\", \"hello\": \"world\"}",
            new FixedJson("{\"notes_text\": \"\"\", \"hello\": \"world\"}").value()
        );
    }

    @Test
    public void valueWithTwoDoubleQuotes() {
        assertEquals(
            "{\"notes_text\": \"\\\"\\\"\"}",
            new FixedJson("{\"notes_text\": \"\"\"\"}").value()
        );
    }

    @Test
    public void valueWithTwoDoubleQuotesAndAnotherValue() {
        assertEquals(
            "{\"notes_text\": \"\\\"\\\"\", \"hello\": \"world\"}",
            new FixedJson("{\"notes_text\": \"\"\"\", \"hello\": \"world\"}").value()
        );
    }

    @Test
    public void valueWithOneSlash() {
        assertEquals(
            "{\"notes_text\": \"\\\\\"}",
            new FixedJson("{\"notes_text\": \"\\\"}").value()
        );
    }

    @Test
    public void valueWithOneSlashAndAnotherValue() {
        assertEquals(
            "{\"notes_text\": \"\\\\\", \"hello\": \"world\"}",
            new FixedJson("{\"notes_text\": \"\\\", \"hello\": \"world\"}").value()
        );
    }

    @Test
    public void valueWithTwoSlashes() {
        assertEquals(
            "{\"notes_text\": \"\\\\\\\\\"}",
            new FixedJson("{\"notes_text\": \"\\\\\"}").value()
        );
    }

    @Test
    public void valueWithTwoSlashesAndAnotherValue() {
        assertEquals(
            "{\"notes_text\": \"\\\\\\\\\", \"hello\": \"world\"}",
            new FixedJson("{\"notes_text\": \"\\\\\", \"hello\": \"world\"}").value()
        );
    }
}
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class EscapedTest {

    @Test
    public void doubleQuotesTest() {
        assertEquals(
            new Escaped("\"").value(),
            "\\\""
        );
        assertEquals(
            new Escaped("abc\"def").value(),
            "abc\\\"def"
        );
    }

    @Test
    public void slashesTest() {
        assertEquals(
            new Escaped("\\").value(),
            "\\\\"
        );
        assertEquals(
            new Escaped("abc\\def").value(),
            "abc\\\\def"
        );
    }

    @Test
    public void mixedTest() {
        assertEquals(
            new Escaped("\\\"").value(),
            "\\\\\\\""
        );
        assertEquals(
            new Escaped("abc\\\"def").value(),
            "abc\\\\\\\"def"
        );
    }
}

Full working example

import java.util.regex.Pattern;

public class FixedJsonExample {
    public static void main(String[] args) {
        String invalidJson = "{\"notes_text\":\"\"\"}";

        final String fixedJson = new FixedJson(invalidJson).value();
        System.out.println("fixedJson = " + fixedJson);
    }


    public static class FixedJson {

        private final String target;

        private final Pattern pattern;

        public FixedJson(String target) {
            this(
                target,
                Pattern.compile("\"(.+?)\"[^\\w\"]")
            );
        }

        public FixedJson(String target, Pattern pattern) {
            this.target = target;
            this.pattern = pattern;
        }

        public String value() {
            return this.pattern.matcher(this.target).replaceAll(
                matchResult -> {
                    StringBuilder sb = new StringBuilder();
                    sb.append(
                        matchResult.group(),
                        0,
                        matchResult.start(1) - matchResult.start(0)
                    );
                    sb.append(
                        new Escaped(
                            new Escaped(matchResult.group(1)).value()
                        ).value()
                    );
                    sb.append(
                        matchResult.group().substring(
                            matchResult.group().length() - (matchResult.end(0) - matchResult.end(1))
                        )
                    );
                    return sb.toString();
                }
            );
        }
    }

    public static class Escaped {

        private final String target;

        private final Pattern pattern;

        public Escaped(String target) {
            this(
                target,
                Pattern.compile("[\\\\\"]")
            );
        }

        public Escaped(String target, Pattern pattern) {
            this.target = target;
            this.pattern = pattern;
        }

        public String value() {
            return this.pattern
                .matcher(this.target)
                .replaceAll("\\\\$0");
        }
    }
}

And its STDOUT:

fixedJson = {"notes_text":"\""}

This JSON can be validated using following tool: https://jsonlint.com/

Regex explanation

FixedJson class

The first class FixedJson uses regexp for matching JSON lemmas: everything between double quotes (include misplaced double quotes).

For more details see an interactive example here: https://regexr.com/54blf

Escaped class

The second class Escaped uses regexp for matching slashes or double quotes. It's required for their escaping.

For more details see an interactive example here: https://regexr.com/54bm1

🌐
Baeldung
baeldung.com › home › json › escape json string in java
Escape JSON String in Java | Baeldung
January 8, 2024 - JSONObject jsonObject = new JSONObject(); jsonObject.put("message", "Hello \"World\""); String payload = jsonObject.toString(); This will take the quotes around “World” and escape them: ... One of the most popular and versatile Java libraries for JSON processing is Jackson.