Home > Software design >  Accessing a Numeric Key in Json Return Using Laravel
Accessing a Numeric Key in Json Return Using Laravel

Time:11-09

I have a geocoding application that is returning me a large JSON array with tons of values. I am trying to drill down to one value called Census_Tract. Right now, I have been able to drill down several levels using the followingin Laravel.

dd($response->results[0]->response->results[0]->fields->census);

that resurns a small JSON array that looks like this:

{#669 ▼
   "2019": {#666 ▼
     "census_year": 2019
     "state_fips": "09"
     "county_fips": "09001"
     "tract_code": "100300"
     "block_code": "1061"
     "block_group": "1"
     "full_fips": "090011003001061"
     "place": null
     "metro_micro_statistical_area": {#667 ▶}
     "combined_statistical_area": {#668 ▶}
     "metropolitan_division": null
     "source": "US Census Bureau"
  }
}

How do I get past the 2019 numeric key? I keep getting the following error:

unexpected integer "2019"

Thanks in advance.

CodePudding user response:

You can use:

$response= $response->results[0]->response->results[0]->fields->census;
var_dump($response->{'2019'});
  • Related