You need to sign in to do that
Don't have an account?

How to convert JSON string to required JSON string?
Hi ,
I'm trying to parse Account records to JSON string. But I'm getting unnecessary data like attributes(type,url) that is not required in String.
Can any one pls help me in how to parse the string to required format.
My requirement is to generate resulting String as below JSON string format.
So that I can minimize the data to to be sent the the client system.
Any help is really appreciated. Thanks in advance.
Regards,
Naveen.
I'm trying to parse Account records to JSON string. But I'm getting unnecessary data like attributes(type,url) that is not required in String.
Can any one pls help me in how to parse the string to required format.
List<Account> accnts=[Select Name,Phone From Account]; String s=JSON.serialize(accnts);The resulting output is in below fromat..
{ "attributes" : { "type" : "Account", "url" : "/services/data/v34.0/sobjects/Account/00128000002trGGAAY" }, "Name" : "GenePoint", "Phone" : "(650) 867-3450", "Id" : "00128000002trGGAAY" }
My requirement is to generate resulting String as below JSON string format.
{ "Name" : "GenePoint", "Phone" : "(650) 867-3450", "Id" : "00128000002trGGAAY" }
So that I can minimize the data to to be sent the the client system.
Any help is really appreciated. Thanks in advance.
Regards,
Naveen.
You can try Json Generator class to build json string which is 2nd way to create json in apex. Here is link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsongenerator.htm
Thanks!
All Answers
You can try Json Generator class to build json string which is 2nd way to create json in apex. Here is link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsongenerator.htm
Thanks!
And then modify your class like this
NOTE:- I created this code for single record. Can can create the array for warpper class. I created this code in notepad may be you will get some sytex error.
Please let us know if this will help you
Thanks,
Amit Chaudhary
Please let me know how can I mark both answers as best answers..
you can use a replace method to replace the unwanted data with a white space like below :
s.val().replace(/\\/g, ''));
in my case i was have to take a string to the page as json but i was getting these term extra so in java script i used this method replace().