A few mistakes here.
Let me explain one by one, giving tips to find common errors in PHP JSON decode / encode.
1. Invalid JSON
First, your JSON is not valid, it has no end } at the end.
Update : right after the @tftd comment, I saw that you formatted your code incorrectly, but in any case, let me explain how to find the problems, because this is not the way it should be in PHP. The remaining errors are still valid.
To check why json_decode is not working, use json_last_error : it will return an error number, which means:
0 = JSON_ERROR_NONE = "No error has occurred" 1 = JSON_ERROR_DEPTH = "The maximum stack depth has been exceeded" 2 = JSON_ERROR_STATE_MISMATCH = "Invalid or malformed JSON" 3 = JSON_ERROR_CTRL_CHAR = "Control character error, possibly incorrectly encoded" 4 = JSON_ERROR_SYNTAX = "Syntax error" 5 = JSON_ERROR_UTF8 = "Malformed UTF-8 characters, possibly incorrectly encode" 6 = JSON_ERROR_RECURSION = "One or more recursive references in the value to be encoded" 7 = JSON_ERROR_INF_OR_NAN = "One or more NAN or INF values in the value to be encoded" 8 = JSON_ERROR_UNSUPPORTED_TYPE = "A value of a type that cannot be encoded was given"
In your case, it returned 4 . So, I passed the JSON check at http://jsonlint.com and I found the missing } at the end.
2. json_decode returns objects, not arrays
If you want to access a single $pname as array, you will need your json_decode string:
$pname = json_decode(file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v002/?key=KEYCONSORED&Steamids={$_SESSION['T2SteamID64']}"), true);
Note the last true parameter for the json_decode method. According to the documentation , when true , the returned objects will be converted to associative arrays.
3. players are an array
The call to JSON and json_decode , we can see that players is an array. So, if you want to read the first player, use:
$pname['response']['players'][0]
Fixed code
I do not read the URL, so I used heredoc :
<?php $content = <<<EOD { "response": { "players": [ { "steamid": "76561198137714668", "communityvisibilitystate": 3, "profilestate": 1, "personaname": "UareBugged", "lastlogoff": 1418911040, "commentpermission": 1, "profileurl": "http://steamcommunity.com/id/uarenotbest/", "avatar": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21.jpg", "avatarmedium": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21_medium.jpg", "avatarfull": "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/da/daece8a16d866ef9bd03ddc4aa365c5862af1c21_full.jpg", "personastate": 1, "realname": "Michal ล lesรกr", "primaryclanid": "103582791436765601", "timecreated": 1400861961, "personastateflags": 0, "loccountrycode": "SK", "locstatecode": "08" } ] } } EOD; $pname = json_decode($content, true); echo $pname['response']['players'][0]['personaname'];
This will be output, as expected, UareBugged .