title: Escaping special characters for JSON output
body: <p>I have a column that contains data that I want to escape in order to use it as JSON output, to be more precise am trying to escape the same characters listed here but using Oracle 11g: <a href="https://msdn.microsoft.com/en-us/library/dn921889.aspx" rel="noreferrer">Special Characters and JSON Escaping Rules</a></p>
  
  <p>I think it can be solved using REGEXP_REPLACE:</p>
  
  <pre><code>SELECT REGEXP_REPLACE(my_column, '("|\\|/)|(' || CHR(9) || ')', '\\\1') FROM my_table;
  </code></pre>
  
  <p>But I am lost about replacing the other characters (tab, new line, backspace, etc), in the previous example I know that \1 will match and replace the first group but I am not sure how to capture the tab in the second group and then replace it with \t.  Somebody could give me a hint about how to do the replacement?</p>
  
  <p>I know I can do this:</p>
  
  <pre><code>SELECT REGEXP_REPLACE( REGEXP_REPLACE(my_column, '("|\\|/)', '\\\1'), '(' || CHR(9) || ')', '\t') 
  FROM my_table;
  </code></pre>
  
  <p>But I would have to nest like 5 calls to REGEXP_REPLACE, and I suspect I should be able to do it in just one or two calls.</p>
  
  <p>I am aware about other packages or libraries for JSON but I think this case is simple enough that it can be solved with the functions that Oracle offers out-of-the-box.</p>
  
  <p>Thank you.</p>