Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to create JSON object composed of objects

    I'm trying to code a JSON access control list field in an MongoDB object database.

    The acl entry should end up containing something like this (this example was taken from the product documentation):

    {
    "4ffcfd9fe4b0211629c4ad06": { "read": true, "write": true },
    "*" : { "read" : true }
    }

    I'm interpreting this to be an acl object consisting of two acl-entry objects. The first acl-entry states that a particular user-id can read and write the record. The second acl-entry states that all users can read the record. I don't have a problem with the concept of an acl or what it is supposed to contain. My question is about how I would construct the above object.

    I'm using this code in a function but the program is hanging. I guess I've made a big error but I don't know enough to know what's wrong.

    Code:
    var user_id = '4ffcfd9fe4b0211629c4ad06';
    var acl = {};
    var author = {};
    var everyone = {};
    
    author[user_id] = { "read": true, "write": true };
    everyone['*'] = {  "read" :  true };
    acl[] = {everyone , author};
    return acl;
    JSLint complains that about the comma on the 2nd last line. I guess that's where I'm doing something stupid.

    I'd be so grateful if someone could correct my misinterpretation and suggest the proper code.

    Many thanks in advance.

  • #2
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile The pretty obvious solution

    OK. I now realise that was a very stoopid question. Still, someone might benefit by seeing the answer so here it is...

    All I had to do (once I got my brain functioning) was the folllowing:

    Code:
    var acl = {};
    
    acl[value] = { "read": true, "write": true };
    acl['*'] = {  "read" :  true };
    
    return acl;


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •