This is more of a concept question than an actual code question but can you deserialize just part of a JSON String into an object or do you have create a class and a sub class for the whole thing. So lets say I have a JSON response like:

    "employee": {  
        "name":       "sonoo",   
        "salary":      56000,   
        "married":    true  

If I wanted to just get data for say just salary could I create a class like this and it still work properly?

    public class Employee {
        public Integer salary;

1 Answer 1


If you deserialize into an object that is a subset of the fields in the incoming payload, it works just fine.

Employee emp = (Employee) JSON.deserialize(thepayload,Employee.class);

name and married will be ignored.

  • Great, Thanks for the clarification.
    – Jebert
    Commented Oct 17, 2022 at 16:47

You must log in to answer this question.

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