title: Recommended way to send SQL like string to backend server in javascript
body: <p>I am struggling to find a good way to send user entered SQL like search criteria to the backend server.</p>
  
  <p>I have an angular application with Spring (java) based backend and Oracle DB. Backend server exposes REST service to receive this input.</p>
  
  <p>User can enter following search string in a text area (user gets help to create this search string). My goal is to send following example search criteria to backend server.</p>
  
  <pre><code>'Customer Name' == 'John Doe' AND 'Customer ID' == 123 AND 'Department' == ('Engineering' OR 'Sales')
  </code></pre>
  
  <p>One Approach I can think of is converting this SQL like text string into JSON object and send it to server.</p>
  
  <p>In this case, how will a string with operands be converted into a JSON object? Can I convert the above example string into a JSON object like below?</p>
  
  <pre><code>{
    "AND": {
      "operation1": "'Customer Name' == 'John Doe'",
      "operation2": "Customer ID' == 123",
      "operation3": {
        "OR":{
          "operation4":"'Department' == 'Engineering'",
          "operation5":"'Department' == 'Sales'"
        }
      }
    }
  }
  </code></pre>
  
  <p>Problem with this object is, it looks too specific to this case and will be difficult for the server to sanitize the input and convert it back into an actual query string.</p>
  
  <p>Also I can not just send this string as is to the backend as there will be XSS or SQL injection issues.</p>
  
  <p>Can some one suggest a way to send this data to backend? if JSON approach is a good approach, is there a better way to convert the above string to a JSON object?   </p>