Skip to main content
Can anyone help me in creating below JSON using javascript? I have all values but unable to create a JSON.

UserId1 and UserId2 is nothing but Salesforce user ids.

{

"UserId1": {

"Account": "Private",

"Contact": "Private",

"Oppor": "Private",

"Case": "Private",

"Team": "--None--"

},

"UserId2": {

"Account": "Private",

"Contact": "Private",

"Oppor": "Private",

"Case": "Private",

"Team": "--None--"

}

}

I have used this way to create this JSON but was not able to create it.

var finalJSON = { };

finalJSON.userId = <UserIdValue>;

finalJSON.userId = '{"Account": "'+Account+'","Contact": "'+Contact+'","Opportunity": "'+Opportunity+'","Case": "'+Case+'","Team": "'+Team+'"}';

 
3 answers
  1. Jun 30, 2015, 6:39 AM

    Hello Saransh,

    Try following Code:

    If its helps, please mark as best answer so it will help to other who will serve same problem.

    ​Thanks! 

    function getJSON(){

    var JSONObject = new Object();

    var UserId1 = new Object();

    UserId1.Account = 'Private';

    UserId1.Contact = 'Private';

    UserId1.Oppor = 'Private';

    UserId1.Case = 'Private';

    UserId1.Team = '--None--';

    var UserId2 = new Object();

    UserId2.Account = 'Private';

    UserId2.Contact = 'Private';

    UserId2.Oppor = 'Private';

    UserId2.Case = 'Private';

    UserId2.Team = '--None--';

    JSONObject.UserId1 = UserId1;

    JSONObject.UserId2 = UserId2;

    return JSON.stringify(JSONObject);

    }

0/9000