1

The question is a rather simple one. It gets me every time when I'm writing JSON manually for e.g. a REST call.

Why are attribute names in JSON quoted? why cant I just write

{
    foo: "bar"
}

but instead have to write

{
    "foo": "bar"
}

On JSON.org thy show that attribute names must be Strings but this doesn't answer this question.

I think this is especially confusing since JSON always is promoted as super lightweight and with much less overhead compared to XML (e.g. here), but wouldn't it be even fewer overhead when they never decided that attribute names have to be quoted?

Also, it would be more like the Javascript Syntax for Dictionaries (jeah, Objects whatever) since there both ways are allowed.

The only disadvantage that I can see would be that you can't use XML style namespacing like:

{
    "foo:bar": "baz"
}

but then again, why bother? you can't really namespace like this in json anyways.

I don't want to say that with the quotes it should be invalid, but I think it makes more sense if they would be optional since 99% of the time (except you convert xml to json) you don't need them and it would save some bytes. Also then the Javascript Object Notation would be closer to how you notate Objects in Javascript.

Can anyone give an educated guess on why this design decicion was made?

Community
  • 1
  • 1
chuck258
  • 912
  • 7
  • 16
  • 1
    In a line - because of identifiers in older browsers , stuff like `{ delete: 15 }` wasn't allowed and that caused issues so it was decided to have uniform syntax so not every person with every language would have to remember JS quirks. – Benjamin Gruenbaum Apr 15 '15 at 12:52
  • Ok, so you have any link to the old question? – chuck258 Apr 16 '15 at 06:33

0 Answers0