which is missing the quotes around foo so it should be:
{"foo": "bar"}
Since both of those would have had the same meaning the JSON spec sensibly restricts things so that only one is valid. See http://json.org/ for the (very short and readable) spec.
The reason for outlawing the first syntax is that it isn't a legal javascript literal in the case where the key is a javascript reserved word (if we change 'foo' to 'for' in this example).
Comments
The malformed example given is:
which is missing the quotes around foo so it should be: Since both of those would have had the same meaning the JSON spec sensibly restricts things so that only one is valid. See http://json.org/ for the (very short and readable) spec.The reason for outlawing the first syntax is that it isn't a legal javascript literal in the case where the key is a javascript reserved word (if we change 'foo' to 'for' in this example).
Thanks.