please help me, I need a method for json string which contains null value and does not contain attributes{ }.
Here's what I currently have:
List<Contact> contacts = [SELECT Id, Name, account.name,account.Id,account.ParentId FROM Contact limit 3];
system.debug(json.serialize(contacts));
which returns a jsonString that looks like this:
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v31.0/sobjects/Contact/003900000115sPwAAI"
},
"Name" : "Rose Gonzalez",
"AccountId" : "00190000010GvcLAAS",
"Account" : {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v31.0/sobjects/Account/00190000010GvcLAAS"
},
"Name" : "Edge Communications",
"Id" : "00190000010GvcLAAS"
},
"Id" : "003900000115sPwAAI"
}, {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v31.0/sobjects/Contact/003900000115sPxAAI"
},
"Name" : "Sean Forbes",
"AccountId" : "00190000010GvcLAAS",
"Account" : {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v31.0/sobjects/Account/00190000010GvcLAAS"
},
"Name" : "Edge Communications",
"Id" : "00190000010GvcLAAS"
},
"Id" : "003900000115sPxAAI"
}, {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v31.0/sobjects/Contact/003900000115sPyAAI"
},
"Name" : "Jack Rogers",
"AccountId" : "00190000010GvcMAAS",
"Account" : {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v31.0/sobjects/Account/00190000010GvcMAAS"
},
"Name" : "Burlington Textiles Corp of America",
"Id" : "00190000010GvcMAAS"
},
"Id" : "003900000115sPyAAI"
} ]
What I need is help putting what I've written above into something that will return a string in a format that looks like what's below:
{
"Name" : "Rose Gonzalez",
"AccountId" : "00190000010GvcLAAS",
"Account" : {
"Name" : "Edge Communications",
"Id" : "00190000010GvcLAAS",
"ParentId":null
},
"Id" : "003900000115sPwAAI"
}, {
"Name" : "Sean Forbes",
"AccountId" : "00190000010GvcLAAS",
"Account" : {
"Name" : "Edge Communications",
"Id" : "00190000010GvcLAAS",
"ParentId" :null
},
"Id" : "003900000115sPxAAI"
}, {
"Name" : "Jack Rogers",
"AccountId" : "00190000010GvcMAAS",
"Account" : {
"Name" : "Burlington Textiles Corp of America",
"Id" : "00190000010GvcMAAS",
"ParentId" :null
},
"Id" : "003900000115sPyAAI"
} ]