var jsonStr="{name:'abc',age:20}";
var jsonObject = (new Function( "return " + jsonStr ) )() ;
console.log(jsonObject);
For further actions, you may consider blocking this person and/or reporting abuse
var jsonStr="{name:'abc',age:20}";
var jsonObject = (new Function( "return " + jsonStr ) )() ;
console.log(jsonObject);
For further actions, you may consider blocking this person and/or reporting abuse
That's fine, you can still create an account and turn on features like 🌚 dark mode.
Dany Paredes -
Nikola Geneshki -
Code of Relevancy -
Stefan -
Once suspended, sandeepkamboj12 will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, sandeepkamboj12 will be able to comment and publish posts again.
Once unpublished, all posts by sandeepkamboj12 will become hidden and only accessible to themselves.
If sandeepkamboj12 is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Sandeep kamboj.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community 👩💻👨💻 safe. Here is what you can do to flag sandeepkamboj12:
Unflagging sandeepkamboj12 will restore default visibility to their posts.
Top comments (4)
JSON.parse would yield a syntax error in this example, because jsonStr is not acutally JSON, since JSON requires double quotes for string, and requires the keys to be in string form as well.
But what is much more grave, this function is prone to script injection.
`
yes. this code is also used for script injection.
I have checked jquery parseJSON method in jquery library in 1.x version. It also uses this technique to parse json..
Just to be perfectly clear: script injection is not a feature, it is a security vurnerabilty. And that jQuery, in an apparently rather old version, did this in its days, is no excuse to repeat the mistake in 2018.
right and what would be the best way to do that since JSON.parse doesn't work because it has a function?
I ask that because I have a very similar scenario.