Yes in ES2015, no in ES5, but first allow one thing: JavaScript, not JSON.
In ES2015 (formerly known as ES6):
var something = "foo"; var object = { [something]: "bar"; }; alert(object.foo);
Inside [ ] can be any expression that you like. The return value is coerced to the string. That means you have hours of fun with things like
var counter = function() { var counter = 1; return function() { return counter++; }; }; var object = { ["property" + counter()]: "first property", ["property" + counter()]: "second property" }; alert(object.property2);
JSON is a serialization format based on the syntax of a JavaScript object initializer. There is no way in JSON to do anything like this.
source share