php json get variable from response

Using the following code, I get a JSON response back:

code:
<?php ...
$responseData = json_decode($response, TRUE);
echo $response;
... ?>

Open in new window


response:
{
  "Id": "777cc42f-7819-476b-b852-bf8ebbd88af7",
  "DeviceName": "scannerName",
  "ScanType": "ScannerSimplex",
  "ImageProcessingOverrides": {
    "DoRotateAndCrop": false,
    "DoMirrorCrop": false
  },
  "ImagesToDownload": "IndividualImages",
  "IsFinished": true,
  "IsFaulted": false,
  "IsDataExtracted": true,
  "ElapsedSeconds": 0,
  "OutputFormat": "Jpg",
  "InputImage1": {
    
  },
  "ProcessedImage1": {
    "Bytes": "..."
  },
  "CardCategory": "Health Insurance Card",
  "CardType": "HealthInsurance",
  "HealthInsuranceInfo": {
    "MedicalClaimsAddress": {
      "Name": "Medical Claims Address",
      "Source": "None",
      "Line1": {
        "Name": "Medical Claims Address Line1",
        "Source": "None",
        "Text": ""
      },
      "Line2": {
        "Name": "Medical Claims Address Line2",
        "Source": "None",
        "Text": ""
      },
      "City": {
        "Name": "Medical Claims Address City",
        "Source": "None",
        "Text": ""
      },
      "State": {
        "Name": "Medical Claims Address State",
        "Source": "None",
        "Text": ""
      },
      "ZipCode": {
        "Name": "Medical Claims Address Zip Code",
        "Source": "None",
        "Text": ""
      }
    },
    "EffectiveDate": {
      "Name": "Effective Date",
      "Source": "None",
      "Month": {
        "Name": "Effective Date Month",
        "Source": "None",
        "Text": ""
      },
      "Day": {
        "Name": "Effective Date Day",
        "Source": "None",
        "Text": ""
      },
      "Year": {
        "Name": "Effective Date Year",
        "Source": "None",
        "Text": ""
      }
    },
    "CustomerService": {
      "Name": "Customer Service",
      "Source": "None",
      "CountryCode": {
        "Name": "Customer Service Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Customer Service Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Customer Service Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Customer Service Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Customer Service Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "IdNumber": {
      "Name": "Id Number",
      "Source": "OCR",
      "Text": "ABCD12345"
    },
    "SubscriberName": {
      "Name": "Subscriber Name",
      "Source": "OCR",
      "First": {
        "Name": "Subscriber Name First",
        "Source": "OCR",
        "Text": "JOHN"
      },
      "Middle": {
        "Name": "Subscriber Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Subscriber Name Last",
        "Source": "OCR",
        "Text": "DOE"
      },
      "Suffix": {
        "Name": "Subscriber Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient2Name": {
      "Name": "Patient 2 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 2 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 2 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 2 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 2 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient3Name": {
      "Name": "Patient 3 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 3 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 3 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 3 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 3 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient4Name": {
      "Name": "Patient 4 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 4 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 4 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 4 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 4 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient5Name": {
      "Name": "Patient 5 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 5 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 5 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 5 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 5 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient6Name": {
      "Name": "Patient 6 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 6 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 6 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 6 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 6 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "EmergencyCopay": {
      "Name": "Emergency Copay",
      "Source": "None",
      "Amount": {
        "Name": "Emergency Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Emergency Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "Employer": {
      "Name": "Employer",
      "Source": "None",
      "Text": ""
    },
    "GroupNumber": {
      "Name": "Group Number",
      "Source": "OCR",
      "Text": "XYZ"
    },
    "MedicalDeductible": {
      "Name": "Medical Deductible",
      "Source": "None",
      "Amount": {
        "Name": "Medical Deductible Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Medical Deductible Type",
        "Source": "None",
        "Text": ""
      }
    },
    "OfficeCopay": {
      "Name": "Office Copay",
      "Source": "None",
      "Amount": {
        "Name": "Office Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Office Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "PayerId": {
      "Name": "Payer Id",
      "Source": "None",
      "Text": ""
    },
    "PlanType": {
      "Name": "Plan Type",
      "Source": "None",
      "Text": ""
    },
    "PreCertifyServices": {
      "Name": "Pre Certify Services",
      "Source": "None",
      "CountryCode": {
        "Name": "Pre Certify Services Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Pre Certify Services Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Pre Certify Services Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Pre Certify Services Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Pre Certify Services Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "RxBin": {
      "Name": "RXBIN",
      "Source": "OCR",
      "Text": "63"
    },
    "RxGrp": {
      "Name": "RXGRP",
      "Source": "None",
      "Text": ""
    },
    "RxPcn": {
      "Name": "RXPCN",
      "Source": "OCR",
      "Text": "DV RxGr"
    },
    "SpecialistCopay": {
      "Name": "Specialist Copay",
      "Source": "None",
      "Amount": {
        "Name": "Specialist Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Specialist Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "UrgentCopay": {
      "Name": "Urgent Care Copay",
      "Source": "None",
      "Amount": {
        "Name": "Urgent Care Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Urgent Care Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier1Copay": {
      "Name": "RX Tier 1 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 1 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 1 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier2Copay": {
      "Name": "RX Tier 2 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 2 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 2 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier3Copay": {
      "Name": "RX Tier 3 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 3 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 3 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxDeductible": {
      "Name": "RX Deductible",
      "Source": "None",
      "Amount": {
        "Name": "RX Deductible Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Deductible Type",
        "Source": "None",
        "Text": ""
      }
    },
    "PharmacyService": {
      "Name": "Pharmacy Service",
      "Source": "None",
      "CountryCode": {
        "Name": "Pharmacy Service Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Pharmacy Service Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Pharmacy Service Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Pharmacy Service Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Pharmacy Service Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "MentalHealthPreAuth": {
      "Name": "Mental Health Pre Auth",
      "Source": "None",
      "CountryCode": {
        "Name": "Mental Health Pre Auth Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Mental Health Pre Auth Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Mental Health Pre Auth Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Mental Health Pre Auth Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Mental Health Pre Auth Extension",
        "Source": "None",
        "Text": ""
      }
    }
  }
}

Open in new window


I would like to get a few variables from this and echo them in the PHP:

HealthInsuranceInfo:IdNumber
HealthInsuranceInfo:SubscriberName:First
HealthInsuranceInfo:SubscriberName:Last

How do I do this?
hypervisorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nrupendra Nath PanigrahiCommented:
After decode you will get an PHP array, just go to desired index:

HealthInsuranceInfo:IdNumber :  $responseData[0]['IdNumber']['Name'] or $responseData['IdNumber']['Name']


HealthInsuranceInfo:SubscriberName:First  :   $responseData[0]['SubscriberName']['First']['Name']  /or    $responseData['SubscriberName']['First']['Name']



HealthInsuranceInfo:SubscriberName:Last:     $responseData[0]['SubscriberName']['Last']['Name'] /or  $responseData['SubscriberName']['Last']['Name']


if you are not getting the data with above code than you use the variable name which u assigned in the php code to getting the responce
 ex
your variabe is $variable


$responseData['variable'][0]['SubscriberName']['Last']['Name'] /or  $responseData['variable']['SubscriberName']['Last']['Name']
0
Ray PaseurCommented:
JSON_Decode() will give you an array or an object.  In PHP, both can be used with iterators like foreach() and the choice is up to you, but I find the syntax for objects to be easier to get right.

Please see: http://iconoun.com/demo/temp_hypervisor.php

Moving parts are at the bottom of the script.
<?php // demo/temp_hypervisor.php
/**
 * http://www.experts-exchange.com/questions/28695509/php-json-get-variable-from-response.html
 *
 * I would like to get a few variables from this and echo them in the PHP:
 *   HealthInsuranceInfo:IdNumber
 *   HealthInsuranceInfo:SubscriberName:First
 *   HealthInsuranceInfo:SubscriberName:Last
 */
error_reporting(E_ALL);
echo '<pre>';

// TEST DATA FROM THE POST AT EE
$jso = <<<EOD
{
  "Id": "777cc42f-7819-476b-b852-bf8ebbd88af7",
  "DeviceName": "scannerName",
  "ScanType": "ScannerSimplex",
  "ImageProcessingOverrides": {
    "DoRotateAndCrop": false,
    "DoMirrorCrop": false
  },
  "ImagesToDownload": "IndividualImages",
  "IsFinished": true,
  "IsFaulted": false,
  "IsDataExtracted": true,
  "ElapsedSeconds": 0,
  "OutputFormat": "Jpg",
  "InputImage1": {

  },
  "ProcessedImage1": {
    "Bytes": "..."
  },
  "CardCategory": "Health Insurance Card",
  "CardType": "HealthInsurance",
  "HealthInsuranceInfo": {
    "MedicalClaimsAddress": {
      "Name": "Medical Claims Address",
      "Source": "None",
      "Line1": {
        "Name": "Medical Claims Address Line1",
        "Source": "None",
        "Text": ""
      },
      "Line2": {
        "Name": "Medical Claims Address Line2",
        "Source": "None",
        "Text": ""
      },
      "City": {
        "Name": "Medical Claims Address City",
        "Source": "None",
        "Text": ""
      },
      "State": {
        "Name": "Medical Claims Address State",
        "Source": "None",
        "Text": ""
      },
      "ZipCode": {
        "Name": "Medical Claims Address Zip Code",
        "Source": "None",
        "Text": ""
      }
    },
    "EffectiveDate": {
      "Name": "Effective Date",
      "Source": "None",
      "Month": {
        "Name": "Effective Date Month",
        "Source": "None",
        "Text": ""
      },
      "Day": {
        "Name": "Effective Date Day",
        "Source": "None",
        "Text": ""
      },
      "Year": {
        "Name": "Effective Date Year",
        "Source": "None",
        "Text": ""
      }
    },
    "CustomerService": {
      "Name": "Customer Service",
      "Source": "None",
      "CountryCode": {
        "Name": "Customer Service Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Customer Service Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Customer Service Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Customer Service Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Customer Service Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "IdNumber": {
      "Name": "Id Number",
      "Source": "OCR",
      "Text": "ABCD12345"
    },
    "SubscriberName": {
      "Name": "Subscriber Name",
      "Source": "OCR",
      "First": {
        "Name": "Subscriber Name First",
        "Source": "OCR",
        "Text": "JOHN"
      },
      "Middle": {
        "Name": "Subscriber Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Subscriber Name Last",
        "Source": "OCR",
        "Text": "DOE"
      },
      "Suffix": {
        "Name": "Subscriber Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient2Name": {
      "Name": "Patient 2 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 2 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 2 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 2 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 2 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient3Name": {
      "Name": "Patient 3 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 3 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 3 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 3 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 3 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient4Name": {
      "Name": "Patient 4 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 4 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 4 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 4 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 4 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient5Name": {
      "Name": "Patient 5 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 5 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 5 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 5 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 5 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "Patient6Name": {
      "Name": "Patient 6 Name",
      "Source": "None",
      "First": {
        "Name": "Patient 6 Name First",
        "Source": "None",
        "Text": ""
      },
      "Middle": {
        "Name": "Patient 6 Name Middle",
        "Source": "None",
        "Text": ""
      },
      "Last": {
        "Name": "Patient 6 Name Last",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Patient 6 Name Suffix",
        "Source": "None",
        "Text": ""
      }
    },
    "EmergencyCopay": {
      "Name": "Emergency Copay",
      "Source": "None",
      "Amount": {
        "Name": "Emergency Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Emergency Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "Employer": {
      "Name": "Employer",
      "Source": "None",
      "Text": ""
    },
    "GroupNumber": {
      "Name": "Group Number",
      "Source": "OCR",
      "Text": "XYZ"
    },
    "MedicalDeductible": {
      "Name": "Medical Deductible",
      "Source": "None",
      "Amount": {
        "Name": "Medical Deductible Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Medical Deductible Type",
        "Source": "None",
        "Text": ""
      }
    },
    "OfficeCopay": {
      "Name": "Office Copay",
      "Source": "None",
      "Amount": {
        "Name": "Office Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Office Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "PayerId": {
      "Name": "Payer Id",
      "Source": "None",
      "Text": ""
    },
    "PlanType": {
      "Name": "Plan Type",
      "Source": "None",
      "Text": ""
    },
    "PreCertifyServices": {
      "Name": "Pre Certify Services",
      "Source": "None",
      "CountryCode": {
        "Name": "Pre Certify Services Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Pre Certify Services Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Pre Certify Services Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Pre Certify Services Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Pre Certify Services Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "RxBin": {
      "Name": "RXBIN",
      "Source": "OCR",
      "Text": "63"
    },
    "RxGrp": {
      "Name": "RXGRP",
      "Source": "None",
      "Text": ""
    },
    "RxPcn": {
      "Name": "RXPCN",
      "Source": "OCR",
      "Text": "DV RxGr"
    },
    "SpecialistCopay": {
      "Name": "Specialist Copay",
      "Source": "None",
      "Amount": {
        "Name": "Specialist Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Specialist Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "UrgentCopay": {
      "Name": "Urgent Care Copay",
      "Source": "None",
      "Amount": {
        "Name": "Urgent Care Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "Urgent Care Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier1Copay": {
      "Name": "RX Tier 1 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 1 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 1 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier2Copay": {
      "Name": "RX Tier 2 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 2 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 2 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxTier3Copay": {
      "Name": "RX Tier 3 Copay",
      "Source": "None",
      "Amount": {
        "Name": "RX Tier 3 Copay Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Tier 3 Copay Type",
        "Source": "None",
        "Text": ""
      }
    },
    "RxDeductible": {
      "Name": "RX Deductible",
      "Source": "None",
      "Amount": {
        "Name": "RX Deductible Amount",
        "Source": "None",
        "Text": ""
      },
      "Type": {
        "Name": "RX Deductible Type",
        "Source": "None",
        "Text": ""
      }
    },
    "PharmacyService": {
      "Name": "Pharmacy Service",
      "Source": "None",
      "CountryCode": {
        "Name": "Pharmacy Service Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Pharmacy Service Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Pharmacy Service Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Pharmacy Service Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Pharmacy Service Extension",
        "Source": "None",
        "Text": ""
      }
    },
    "MentalHealthPreAuth": {
      "Name": "Mental Health Pre Auth",
      "Source": "None",
      "CountryCode": {
        "Name": "Mental Health Pre Auth Country Code",
        "Source": "None",
        "Text": ""
      },
      "AreaCode": {
        "Name": "Mental Health Pre Auth Area Code",
        "Source": "None",
        "Text": ""
      },
      "Prefix": {
        "Name": "Mental Health Pre Auth Prefix",
        "Source": "None",
        "Text": ""
      },
      "Suffix": {
        "Name": "Mental Health Pre Auth Suffix",
        "Source": "None",
        "Text": ""
      },
      "Extension": {
        "Name": "Mental Health Pre Auth Extension",
        "Source": "None",
        "Text": ""
      }
    }
  }
}
EOD;


// MAKE AN OBJECT
$obj = json_decode($jso);

// ACTIVATE THIS TO VISUALIZE THE OBJECT
// var_dump($obj);


// SHOW HOW TO GET THE OBJECT ELEMENTS
echo PHP_EOL . 'HealthInsuranceInfo:IdNumber: ';
$idn = $obj->HealthInsuranceInfo->IdNumber;
var_dump($idn);

echo PHP_EOL . 'HealthInsuranceInfo:SubscriberName:First: ';
$snf = $obj->HealthInsuranceInfo->SubscriberName->First;
var_dump($snf);

echo PHP_EOL . 'HealthInsuranceInfo:SubscriberName:Last: ';
$snl = $obj->HealthInsuranceInfo->SubscriberName->Last;
var_dump($snl);


// SHOW HOW TO GET FORMATTED INFORMATION FROM THE OBJECT ELEMENTS
echo PHP_EOL . "$snf->Text $snl->Text HAS ID NUMBER $idn->Text";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hypervisorAuthor Commented:
This solution was the most elegant.  Thank you!
0
Ray PaseurCommented:
Thanks for the points and thanks for using E-E! ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.