Reputation: 43156
Is there any difference between the following title
keys?
jsonObj = {
title: "hello"
}
and
jsonObj = {
"title": "world"
}
Upvotes: 1
Views: 80
Reputation: 522145
As a Javascript object literal (as Javascript code), they're identical.
As the JSON data format, only with quotes is valid JSON.
JSON is a strict subset of Javascript syntax, they're not the same thing.
Upvotes: 3
Reputation: 43245
Both are valid javascript objects, but only second one is a valid JSON object. Preferably use the second one, that also helps when property name is a keyword, or has special characters in it .e.g ":" or space.
jsonObj = {
"my second key::second range":99
}
Upvotes: 2