public class fromJSON{
   public cls_Student[] Student;
   class cls_Student {
       public String Name; //Vinayak
       public String branch;   //Mech
       public String phone;    //909090
   public static fromJSON parse(String json){
       return (fromJSON) System.JSON.deserialize(json, fromJSON.class);

I am trying to print json object into debug log=>

//This is anonymous window code to execute above json.
String js='{"Name":"Vinayak","branch":"Mech","phone":"909090"}';

Getting this result in debug logs => 12:01:17:019 USER_DEBUG [2]|DEBUG|fromJSON:[Student=null]

2 Answers 2


Assuming your requirement is to have an array of students having names, branches, and phones. JSON shall be structured below as

   {"Name": "Vinayak", "branch": "Mech", "phone": "909090"},
   {"Name": "Vinayak 2", "branch": "Mech", "phone": "909091"},
   so on and so forth


In this scenario, your class structure will be

public Class Student{
           public String name; 
           public String branch;   
           public String phone;    

and top-level class will be

public Class StudentsList{
       public List<Student> students; 

and to parse the JSON string you can use

StudentsList students = (StudentsList)System.JSON.deserialize(json, StudentsList.class);
  • Thanks....this is what i want...thank u so much Jun 12, 2022 at 12:28

Your JSON doesn't match your Apex. Your Apex class represents a JSON structure like this:

    "Student": [{"Name": "Vinayak", "branch": "Mech", "phone": "909090"}]

Note the extra level of structure under the key "Student".

Either the JSON example or the Apex is wrong, but I couldn't say which one from the details given in your question. See How do I get started working with JSON in Apex? for introduction and examples.

  • Thanks David for ur response... Jun 12, 2022 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .