1

How come this:

data-something='{property:1}'

doesnt work, but this

data-something='{"property":1}'

does. Does it

1
  • 2
    JSON Spec... Commented Mar 4, 2013 at 22:05

1 Answer 1

5

Because JSON requires that object keys be quoted. This is mandated by the JSON specification; accepting non-quoted keys would mean that the implementation is not JSON-compliant.

This decision was made to side-step the issue of reserved keywords in JavaScript. It was desired that valid JSON also be a valid JavaScript expression, and to make that happen you would have to quote keys like return and function. To simplify specification of the JSON language, it was decided to require that all keys be quoted rather than maintain a list of keys that must be quoted and thereby complicate the JSON grammar (as well as tie the JSON language more closely to the JavaScript language than would otherwise be required).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.