I have this JSON Response, and I'm having trouble trying to figure out both the JSON.deserializeUntyped and JSON Parser. My ultimate goal is that I need to parse the JSON, then take each value and include it into a Detail Page for an object. From what I can tell I need to make a class for the objects in the outer array, and then another wrapper class for the items within those arrays? What I'm confused about is how to isolate each value and get it to the page I want.

JSON Response From HTTP Callout That I Need Help Parsing


Apex Class minus the HTTP callout that I'm leaving out, but works

global class ApexCallout {
    id thisRecId;
    Recommendation_Request__c recParams;
    public String recResponseBody { get; set; }
    Recommendation_Response__c recResponse { get; set; }

    public MicFire(ApexPages.standardController sc){
        thisRecId = ApexPages.currentPage().getParameters().get('id');
        recParams = [SELECT Rest_API_Parms__c FROM Recommendation_Request__c WHERE Id = :thisRecId];
            public class IdealResponse{
                public List<recResponseItems> IdealResponse;

            public class recResponseItems {
                public string product;
                public integer percent;
                public double dollarAmount;

            IdealResponse ideal = (IdealResponse)JSON.deserialize(recResponseBody, IdealResponse.class);

            public class idealFiltered {
                public List<idealFiltered> idealFiltered;

            public class idealFilteredWrapper {
                public string product;
                public integer percent;
                public double dollarAmount;

            public class inBudget {
                public List<inBudget> inBudget;

            public class inBudgetWrapper {
                public string product;
                public integer percent;
                public double dollarAmount;
  • Hi @stephen, could you find a solution for this? Do mark the answer if it worked for you.
    – MnZ
    Commented Aug 12, 2016 at 16:17

1 Answer 1


Using JSON2Apex (here), you can easily generate a class that you can use to deserialize your JSON.

JSON2Apex outputs code like this:

    public class Outer {

    public List<Ideal> ideal;
    public List<Ideal> idealFiltered;
    public List<Ideal> InBudget;

    public class Ideal {
        public String product;
        public String percent;
        public String dollarAmount;

    public static Outer parse(String json) {
        return (Outer) System.JSON.deserialize(json, Outer.class);

From here, you can iterate through the lists inside the main Object and extract the values as you need.

The key is the parse method. What you need to do is pass in your string like this:

Outer myParsedResult = Outer.parse(httpCalloutResponseString);

Then you can literally go:

for (Ideal idealItem : Outer.ideal){
    //do something here... maybe if a value is x, assign that value to your 
    //public property on your vf page etc...
  • I saw this site while researching before asking this question. What I'm more interested in understanding is what this code block is actually doing. And getting at least one example of how to extract the value like I need to do. I've seen this type of code block numerous times on here, but was hoping to get a more in depth answer if possible.
    – Stephen
    Commented Jun 10, 2015 at 2:37
  • 2
    Added a few extra details - hopefully this is helpful Commented Jun 10, 2015 at 2:48
  • @Stephen are you familiar with serialization and deserialization? Commented Jun 10, 2015 at 4:31
  • @PittsburghDBA a little bit, but having trouble isolating each value. Any extensive examples would be really helpful though, instead of small code blocks with partial answers.
    – Stephen
    Commented Jun 10, 2015 at 12:50

You must log in to answer this question.

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