function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saransh Bharadwaj 1Saransh Bharadwaj 1 

JSON!!

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+'"}';


 
Shrikant BagalShrikant Bagal


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);
}




Shrikant BagalShrikant Bagal
If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
Shrikant BagalShrikant Bagal
If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!