title: How to escape double quotes in a JSON in JAVA dynamically
body: <p>How to escape double quotes inside a JSON given the data in the JSON will be obtained dynamically in JAVA</p>
  
  <p>Example:</p>
  
  <pre><code>{
  "key": "I ask silly questions on "https://www.stackoverflow.com". "
  }
  </code></pre>
  
  <p>In this case, the value in the JSON is populated from dynamically let's say from a user input.</p>
  
  <p>I have tried StringEscapeUtils provided by apache-commons-lang (<a href="https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html" rel="nofollow noreferrer">https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html</a>) but this escapes the entire JSON where as the double quotes inside the JSON needs to escape again.</p>
  
  <p>Possible solution will be to use regex and filter out the value in JSON and escape once before escaping the overall JSON. </p>
  
  <p>But, is there any JAR to escape the inner contents of a JSON.</p>