I have a JSON string:
{
"key1": "abc",
"key2": "def",
"key3": "gh\"i\"j"
}
Expected o/p:
{
"key1": "abc",
"key2": "def",
"key3": "ghij"
}
Java string replace() and replaceAll() are replacing all double quotes:
System.out.println(a.replaceAll("\\\"",""));
System.out.println(a.replace("\"",""));
Output:
{
key1: abc,
key2: def,
key3: ghij
}
The reason I'm trying to replace \" is that some operation has to be done using JSON, escaping special characters and storing the JSON string to a database. Here the json becomes invalid because of \".
How can I replace only \" with empty value?