When you do JSON decode the output will be an array format. So try this
$econfig = json_decode(file_get_contents("url.json"),TRUE);
return $econfig["uris"]["DIT"];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello Guys,
I 'm trying to get this value, but having some issues
So I have a file called url.json and i'm loading it here $econfig = json_decode(file_get_contents("url.json"));
The code looks like this
"uris": {
"DIT": "http://test1.com",
"FIT": "http://test2.com",
"UAT": "http://test3.com",
"PROD": "http://test4.com",
"PROD2": "http://test5.com"
},
"endpoints": {
"create": "migrate",
"status": "migrate"
},
"emails": [
]
}
When I do var_dump($econfig) It outputs this
class stdClass#4 (3) {
public $uris =>
class stdClass#5 (5) {
public $DIT =>
string(42) "http://test1.com"
public $FIT =>
string(78) "http://test2.com"
public $UAT =>
string(85) "http://test3com"
public $PROD =>
string(81) "http://test4.com"
public $PROD2 =>
string(81) "http://test5.com/"
}
How can I compare the env, for example "DIT" and get the value (Which in this case is http://test1.com)?
I know it will be something like $econfig>DIT;
Help is appreciated.
As you can see form the dumped variable, the DIT property is nested under uris object, so you would use:
$econfig->uris->DIT
The laravel helper data_get would be useful in this context; in the event that part of the chain of properties does not exist, you would not get an error:
data_get($econfig, 'uris.DIT')
It has the advantage of working transparently for Objects and Arrays.
Please or to participate in this conversation.