code: private String escapeString(String value)
     {
        m_buffer.setLength(0);
        m_buffer.append('"');
        for (int index = 0; index < value.length(); index++)
        {
           char c = value.charAt(index);
           switch (c)
           {
              case '"':
              {
                 m_buffer.append("\\\"");
                 break;
              }
  
              case '\\':
              {
                 m_buffer.append("\\\\");
                 break;
              }
  
              case '/':
              {
                 m_buffer.append("\\/");
                 break;
              }
  
              case '\b':
              {
                 m_buffer.append("\\b");
                 break;
              }
  
              case '\f':
              {
                 m_buffer.append("\\f");
                 break;
              }
  
              case '\n':
              {
                 m_buffer.append("\\n");
                 break;
              }
  
              case '\r':
              {
                 m_buffer.append("\\r");
                 break;
              }
  
              case '\t':
              {
                 m_buffer.append("\\t");
                 break;
              }
  
              default:
              {
                 // Append if it's not a control character (0x00 to 0x1f)
                 if (c > 0x1f)
                 {
                    m_buffer.append(c);
                 }
                 break;
              }
           }
        }
        m_buffer.append('"');
        return m_buffer.toString();
     }
docs: Escape text to ensure valid JSON.
  
  @param value value
  @return escaped value