Outputing nested JSON response in HTML

I am trying to output nested JSON response in html but only part of the JSON is outputing. Have been able to output the following

/*Initializing temp variable to design table dynamically*/
       $temp = "<table>";
              
       /*Dynamically generating rows & columns*/
       for($i = 0; $i < sizeof($response["SMARTScores"]); $i++)
       {
       $temp .= "<tr>";
       $temp .= "<tr><td> <strong> Registry_ID: </strong></td> <td>" . $response["SMARTScores"][$i]["Registry_ID"] . "&nbsp;</td>";
       $temp .= "<tr><td> <strong> BVN: </strong></td> <td>" . $response["SMARTScores"][$i]["BVN"] . "&nbsp;</td>";
       $temp .= "<tr><td> <strong> Score: </strong></td> <td>" . $response["SMARTScores"][$i]["Score"] . "&nbsp;</td>";
       $temp .= "</tr>";
       }
       
       /*End tag of table*/
       $temp .= "</table>";

       
       /*Printing temp variable which holds table*/
       echo $temp;

I am having challenges outputing the following headers “PerformanceSummary” and “PDFReport” See the full raw JSON response body below

Response Body
{
  "Success": true,
  "Errors": [],
  "SMARTScores": [
    {
      "Registry_ID": "12345678098766554",
      "BVN": "123456789098",
      "Score": 97
    }
  ],
  "Accounts": [],
  "PerformanceSummary": {
    "Inquiry_Count_12_Months": 0,
    "Count_AccountStatus_Closed": 0,
    "Count_AccountStatus_Delinquent_30_over_60_days": 0,
    "Count_AccountStatus_Derogatory_120_days": 0,
    "Count_AccountStatus_Derogatory_150_days": 0,
    "Count_AccountStatus_Derogatory_Doubtful_180": 0,
    "Count_AccountStatus_Derogatory_Lost_360": 0,
    "Count_AccountStatus_Derogatory_Substandard_90": 0,
    "Count_AccountStatus_Late_less_than_30_days": 0,
    "Count_AccountStatus_Open": 0,
    "Count_AccountStatus_Performing": 0,
    "Count_AccountStatus_Unknown": 0,
    "Count_AccountStatus_Unspecified": 0,
    "Count_AccountStatus_Written_off": 0,
    "Count_LegalStatus_Judgment": 0,
    "Count_LegalStatus_Litigation": 0,
    "Count_LegalStatus_Notice": 0,
    "Count_LegalStatus_Receivership": 0,
    "SelfInquiriesLast12Months": "N/A",
    "DishonouredChequesLast12Months": "N/A"
  },
  "AccountSummaries": [],
  "PDFReport": {
    "Success": false,
    "Errors": [
      "Invalid model state.",
      "Customer(s) or valid ReportType not specified."
    ],
    "PDFContent": "",
    "NoMatchPDFContent": "",
    "ReportNo": "",
    "Filename": "",
    "StatusCode": 400,
    "Message": ""
  },
  "StatusCode": 200,
  "Message": "Successfully ordered account, account summary and score data for 0 account(s) and 1 customer(s)."
}

Kindly help

You may want to look into foreach:

foreach ($response['PerformanceSummary'] as $key => $value) {
}

Also, your table is messed up. It should be

for($i = 0; $i < sizeof($response["SMARTScores"]); $i++)
       {
       $temp .= "<tr><td> <strong> Registry_ID: </strong></td> <td>" . $response["SMARTScores"][$i]["Registry_ID"] . "&nbsp;</td></tr>";
       $temp .= "<tr><td> <strong> BVN: </strong></td> <td>" . $response["SMARTScores"][$i]["BVN"] . "&nbsp;</td></tr>";
       $temp .= "<tr><td> <strong> Score: </strong></td> <td>" . $response["SMARTScores"][$i]["Score"] . "&nbsp;</td></tr>";
       }

i.e., don’t wrap all <tr> in yet another <tr> and make sure to close every <tr> with a </tr>.

Thank you rpkamp

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.