I'm trying JSON Parser and in the JSON I've \" (for like <tag style=\"color: #fff;\"...) If I can replace \" with \\" the parser works fine (like in this - https://developer.salesforce.com/forums/?id=906F000000092v4IAA)

Input {"name":"Surya\".\""} like name = Surya"."

Output {"name":"Surya\".\""}

String input = '{"name":"Surya\".\""}';

System.debug( input );
//String output = input.replace('\"', '\\\"');
String output = input.replaceAll('\\\"', '\\\\\"');
System.debug( output );

I tried with replace & replaceAll. Please advice me. Thanks.

  • 1
    what is not working that is not clear from your question. Jul 16, 2018 at 5:59
  • Please check the Input & Output and I'm trying few things which are not working for me. Jul 16, 2018 at 10:18

1 Answer 1


If one of the value strings in your JSON is encoded, the simplest and most reliable way to decode is to use a deserialize call:


For your example something like:

String input = '{"name":"Surya\".\""}';
Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(input);

String encodedNameValue = (String) m.get('name');
String nameValue = (String) JSON.deserializeUntyped(encodedNameValue);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .