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
salesforcesss_deveoper211salesforcesss_deveoper211 

JSON Parser to Parse LinkedIn education response

Hi,

Can someone pls help me to derive a method to parse this linkedin education response. I want to store this data into custom sfdc object. Thanks.

{"educations": {
  "_total": 2,
  "values": [
    {
      "activities": "Debate team",
      "degree": "Bachelor of Commerce (B.Com.)",
      "endDate": {"year": 2014},
      "fieldOfStudy": "",
      "id": 219318342,
      "schoolName": "The University of Texas at Austin",
      "startDate": {"year": 2010}
    },
    {
      "endDate": {"year": 2007},
      "id": 219316871,
      "schoolName": "University of California, Los Angeles",
      "startDate": {"year": 2005}
    }
  ]
}}


The method which I developed only captures one set of education data and igonres other, so just wanted to confirm my method. Also how can I parse startDate and endDate into date field of sfdc.

public void parseEduJSON(String JSONEduStr){
        if (JSONEduStr != null){
        linkedInEducation = new List<Education__c>();   
        JSONParser parser = JSON.createParser(JSONEduStr);
      
        while (parser.nextToken() != null)
        {
            if (parser.getCurrentToken() == JSONToken.START_OBJECT)
            {
               while (parser.nextToken() !=  JSONToken.END_OBJECT)
                {
               
                    if (parser.getCurrentToken() == JSONToken.START_ARRAY)
                    {
                        Education__c ei = new Education__c();
                        while (parser.nextToken() !=  JSONToken.END_ARRAY)
                        {
                              if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'activities'))
                                {
                                    parser.nextToken() ;    
                                    ei.Activities__c = parser.getText();
                                }
                                if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'degree'))
                                {
                                    parser.nextToken()     ;
                                    ei.Degree__c = parser.getText();
                                }
                                /*if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'endDate'))
                                {
                                    parser.nextToken()     ;
                                    ei.End_Date__c = parser.getDateValue();
                                }  */
                                if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'fieldOfStudy'))
                                {
                                    parser.nextToken()     ;
                                    ei.Field_of_Study__c = parser.getText();
                                }
                                if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'id'))
                                {
                                    parser.nextToken()     ;
                                    ei.LinkedIn_Educations_ID__c = parser.getText();
                                }
                                if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'schoolName'))
                                {
                                    parser.nextToken()     ;
                                    ei.Name = parser.getText();
                                }
                                /*if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == 'startDate'))
                                {
                                    parser.nextToken()     ;
                                    ei.Start_Date__c = parser.getDateValue();
                                }*/
                              
                        }
                        linkedInEducation.add(ei);
                        system.debug('>>>>>>>>>>>>>>>>final education'+linkedInEducation+'<<<<<<<<<<');
                      
                    }
                }
            }
        }
      
          if(linkedInEducation.size()>0 || linkedInEducation.isEmpty() == False){
           upsert linkedInEducation LinkedIn_Educations_ID__c;
          }
      }   
    }
bob_buzzardbob_buzzard
I would use the JSON2Apex generator fro Superfell and Metadaddy at:

http://json2apex.herokuapp.com/

Just past in your example JSON and it wil generate an Apex class for you.
Giancarlo BaileyGiancarlo Bailey
Thank you so much for these recommendations!
Giancarlo BaileyGiancarlo Bailey
Thank you so much for sharing. It’s very helpful for me. Thank you very much for the information and for providing this manual, which helped me better understand this program and how JSON Parser to Parse LinkedIn education response.  I love the educational process in general at the university and i love to read and books occupy a huge place in my life as they improve me, my knowledge and skills. One of the coolest books that has impressed me lately is The Tempest. This is a play with many themes and motives, which you can read about at https://graduateway.com/essay-examples/the-tempest/ One of the main and most important themes of the entire play will be the theme of Revenge. The concept of revenge is the main object fueling the story and the reason behind Prosperity’s strange actions.