title: Convert complex string(contains objects) to JSON Object?
body: <p>I have a string which is made on run-time depends on user inputs. When user enters some searching criteria the string is creating based on that input and the string is actually an complex objects. When i am trying to <code>JSON.parse()</code> and pass it to the mongoDB find() method to find data in a database and that gives me an error and that is fine. But my object are not a simple key-values pairs actually my objects are key and values are other object to in this case ithink the <code>JSON.parse()</code> method is failing to convert it to a actual JSON Object. I tried some custom implementations as well but i failed alot...</p>
  
  <p><strong>Dynamically Created String</strong></p>
  
  <p><code>"{ "name": { $regex: name, $options: "i" },
  "code": { $regex: code, $options: "i" },
  "phoneNumber": { $regex: phone, $options: "i" },
  "nic": { $regex: cnic, $options: "i"  }"</code></p>
  
  <p>When i try to <code>JSON.parse()</code> it i am getting an error UNEXPECTED token error at position $....</p>
  
  <p><strong>Error Image</strong></p>
  
  <p><a href="https://i.stack.imgur.com/2qIlh.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Help will be appreciated... Thanks in advance  </p>