John Smith John Smith - 2 years ago 109
PHP Question

Targeting object within array JSON Steam API

How do I access

in this Steam API? It's the order
that confuses me, array of one before object? I'm not quite sure about the targeting here..

I've tried:

$gameTrailer = $game_json->57690->data->movies[0]->webm->max;


$gameTrailer = $game_json['57690']['data']['movies']['webm']['max'];

The API text is like this:

"movies": [{
"id": 2029441,
"name": "Tropico 4 Gameplay Trailer",
"thumbnail": "http:\/\/\/steam\/apps\/2029441\/movie.293x165.jpg?t=1447358847",
"webm": {
"480": "http:\/\/\/steam\/apps\/2029441\/movie480.webm?t=1447358847",
"max": "http:\/\/\/steam\/apps\/2029441\/movie_max.webm?t=1447358847"
"highlight": true

and "movies" lies within:

{"57690": {
"data": {

Assume I'll always want the very first movie in an array (which in this case is an array of one). Thanks in advance.

Answer Source

Correct syntax:


When you have an object with a numeric key, you have to wrap the key name by curly brackets (Numeric keys are not valid property names).

If you use the associative option:

json_decode( $data, True );

your second attempt is almost right. Simply add the correct index after movie:

$gameTrailer = $game_json['57690']['data']['movies'][0]['webm']['max'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download