Hi exploring on the JavaScript JSON libraries and as usual I am using Douglas Crockford json2.js
I discover his implementation is very [B]STRICT
First,
[code]
This fail!
myData = JSON.parse(‘{
“a”:100,
“b”:200
}’);
For normal developer, new-line should not be considered as part of the grammar isn’t it ? Above fail the JSON parsing. This is too strict!!! I know the JSON grammar did not mention about new-line but then shouldn’t the implementation be a little lax a bit ?
[code]
This works!
myData = JSON.parse(‘{“a”:100,”b”:200}’);
Second,
[code]
This fail!
myData = JSON.parse(‘{a:100,b:200}’);
[code]
This works!
myData = JSON.parse(‘{“a”:100,”b”:200}’);
For normal developer, the properties in double-quote or not should not be considered as part of the grammar isn’t it ? Above fail the JSON parsing. This is too strict!!! I know the JSON grammar did mention about double-quote but then shouldn’t the implementation be a little lax a bit ?
Conclusion: Anyone has a more “lax abit” JSON grammar implementation besides the one done by Douglas Crockford ? ?
Edit:
json.org mention “Whitespace can be inserted between any pair of tokens. Excepting a few encoding details, that completely describes the language.”
So obviously Douglas interpret whitespace as spaces and tabs but NOT new-lines ?!?!
[code]
This works again!
myData = JSON.parse(‘{ “a”:100, “b”:200 }’);