Saturday, 17 August 2013

JSON syntax - variable being interpreted as a literal

JSON syntax - variable being interpreted as a literal

I run the following code in a JS function. The argument 'value' contains a
user-id string:
function create_acl(value) {
var acl = { value : { "read": true, "write": true}};
return acl;
}
If value = "123" then I'm expecting the result to be:
{ "123": { "read": true, "write": true}}
However, what I'm getting is:
{"value":{"read":true,"write":true}}
As you can see, the code is interpreting 'value' as a literal. Does anyone
know how to rewrite this to get the required behaviour?
Many thanks.
Tom

No comments:

Post a Comment