4 ms·
Because using certain keys could break your JavaScript (and JSON was designed to be a subset), like { delete: "me" } If you don't want to keep a list of k
by xrstf 10y ago
Because using certain keys could break your JavaScript (and JSON was designed to be a subset), like
{ delete: "me" }
If you don't want to keep a list of known keywords around, just insisting on quotes is the easier way.
[EDIT: See also this YouTube video, where Douglas Crockford explains it himself: https://youtu.be/-C-JoyNuQJs?t=5m https://youtu.be/-C-JoyNuQJs?t=5m]
- yepperino 10y agoUnquoted keywords are valid ES5.1 object properties. alert(JSON.stringify({delete: "me", for: 1, var: 2})); results in: {"delete":"me","for":1,"var":2} The only browser it does not work in is IE8 and earlier.
- lucian1900 10y agoJSON significantly predates ES 5.1