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
rumit lumiarumit lumia 

Compare json data


I have two JSON, one I have generated based on my org data, and another I Ihave received from another system.

​​​​​​I have to compare each and every record present in these JSONs. I have unique external ID defined in every record (which can be used while comparing). Finally I have to make a list of similar and dis-simmilar records.

Can anyone suggest, how I can accomplish this task?
Raj VakatiRaj Vakati
You can do like this .. i dnt have a pseudo code 

1. Use JSON to Apex Parser and Generate the Apex Class from  from Source One data ( Lets Suppose You get into the apex class List<SourceOneWrapper> 

2 .Use JSON to Apex Parser and Generate the Apex Class from Source Two data ( Lets Suppose You get into the apex class List<SourceTwoWrapper> 

3 . Create a Temp Apex Class wrapper this value hold the value 
List<FinalApexClassWrapper > wrap = new list<FinalApexClassWrapper > 

4 . Take one of the value as sournce lets take here source one as base 

for( SourceOneWrapper so:LstSouOne){
      For(SourceTwoWrapper so2: so2List){
           if(so2.Id == so.Id){
//add to list
add to another list


Even You can able to use the Maps or Json Deseralixed types based on JSOn format 
rumit lumiarumit lumia
Dear Raj,

Thanks for your response. :)
The above method will surely work for sizeable JSON, and  I'll try to incorporate it.
In my case, the JSONs are huge, I'm scared that it may run into CPU timeouts.
Is there any standard OOTB method defined, which may help me out as my JSONs contains records of standard sObjects.