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 JSON.parse() 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 JSON.parse() method is failing to convert it to a actual JSON Object. I tried some custom implementations as well but i failed alot...
Dynamically Created String
"{ "name": { $regex: name, $options: "i" },
"code": { $regex: code, $options: "i" },
"phoneNumber": { $regex: phone, $options: "i" },
"nic": { $regex: cnic, $options: "i" }"
When i try to JSON.parse() it i am getting an error UNEXPECTED token error at position $....
Error Image
Help will be appreciated... Thanks in advance