I would like to allow users to specify JavaScript object in a HTML textarea which I would then parse. But JSON looks too strict for me, requiring only " as quotes, and quotes everywhere. I would like that you could specify the object in ways you can specify it in JavaScript, and then parse it. How could I parse such string (in JavaScript itself)? Is there a library for it?
I know that I could use eval, but I would not like to allow custom code to run, just static object definition.
I am trying to provide a simple way for users to write MongoDB query.
evalis a simple way. Depending on how exactly the input is used, it won't even be bad (from a security standpoint). Alternatives: Use a JS parser, walk the AST and extract the information you need. Or create your own parser that is a bit more relaxed than JSON (e.g. via pegjs.majda.cz or zaach.github.io/jison).