I have an issue which I've been struggling with today. The JSON is returned back to me with a project Id as the key, this Project Id is dynamically generated and due to this I have not been able to come up with a way to deserialize this response. Any suggestions?


1 Answer 1


You'll need to use a Map as part of the data structure you deserialize to account for the dynamic keys. This allows you to avoid hard-coding the keys as part of your defined structure, which you couldn't do here anyway because they're numeric.

public class Response {
    public class Project {
        String projectId;
        String name;
        String departmentId;
        String responsibleUserId;
    Boolean success;
    Integer numRows;
    Map<String, Project> data;

This structure works to deserialize the JSON you've shown here in a typed way:

JSON.deserialize(myJSON, Response.class));
  • Thank you for taking time out of your day to explain this, really appreciate it. This solved my issue.
    – BreadMAN
    Mar 13, 2019 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.