by greenyoda · 10y ago · 0 comments
{ foo: 1, bar: 2 }
but JSON syntax insists on { "foo": 1, "bar": 2 }
This makes JSON less easily readable by humans, and harder to write or edit by hand.Anyone know why JSON was designed this way?
{ 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]
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.Per my other comment, there are a variety of plugins on the editor side that will make JSON look like this (e.g., vim-json ). To write out to JSON from that format, you can obviously just write a plugin (in JS this is one line).