What is the easiest method to parse "relaxed" JSON but avoid evil eval
?
The following throws an error:
JSON.parse("{muh: 2}");
since proper JSON should have keys quoted: {"muh": 2}
My use case is a simple test interface I use to write JSON commands to my node server. So far I simply used eval
as it's just a test application anyway. However, using JSHint on the whole project keeps bugging me about that eval
. So I'd like a safe alternative that still allows relaxed syntax for keys.
PS: I don't want to write a parser myself just for the sake of the test application :-)
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…