This appears to work:

$url = 'http://www.worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710%22';
$content = file_get_contents(json = json_decode($content, true);

foreach($json['data']['weather'] as $item) {
    print $item['date'];
    print ' - ';
    print $item['weatherDesc'][0]['value'];
    print ' - ';
    print '<img src="' . $item['weatherIconUrl'][0]['value'] . '" border="0" alt="" />';
    print '<br>';
}

If you set the second parameter of json_decode to true, you get an array, so you cant use the -> syntax. I would also suggest you install the JSONview Firefox extension, so you can view generated json documents in a nice formatted tree view similiar to how Firefox displays XML structures. This makes things a lot easier.

Answer from BMBM on Stack Overflow
🌐
PHP
php.net › manual › en › function.json-decode.php
PHP: json_decode - Manual
JSON can be decoded to PHP arrays by using the $associative = true option. Be wary that associative arrays in PHP can be a "list" or "object" when converted to/from JSON, depending on the keys (of absence of them).
🌐
W3Schools
w3schools.com › php › func_json_decode.asp
PHP json_decode() Function
Store JSON data in a PHP variable, and then decode it into a PHP object.
People also ask

Why does json_decode return null?
The JSON is invalid (single quotes, a trailing comma, unquoted keys, a byte order mark), it is nested deeper than the depth limit, or the JSON really is null. Check jsonlasterrormsg(), or decode with JSONTHROWONERROR to get a JsonException with the reason.
🌐
coddy.tech
coddy.tech › docs › php › json_decode()
PHP json_decode(): Parse JSON into Arrays or Objects | Coddy
How do I convert JSON to an array in PHP?
Pass true as the second argument: json_decode('{"name":"Ada"}', true) returns ['name' =&gt; 'Ada'], so you read values with $data['name']. Without true, JSON objects become stdClass objects and you write $data-&gt;name.
🌐
coddy.tech
coddy.tech › docs › php › json_decode()
PHP json_decode(): Parse JSON into Arrays or Objects | Coddy
How do I read a JSON file in PHP?
Read the file, then decode it: $data = jsondecode(filegetcontents('data.json'), true, flags: JSONTHROWONERROR);. filegetcontents() returns false if the file is missing, so check that first.
🌐
coddy.tech
coddy.tech › docs › php › json_decode()
PHP json_decode(): Parse JSON into Arrays or Objects | Coddy
🌐
PHPHub
phphub.net › home › json_decode online
json_decode PHP online
May 11, 2025 - Execute PHP’s json_decode() function. Convert JSON to PHP value quickly and easily with this web-based PHP tool.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-json_decode-function
PHP | json_decode() Function - GeeksforGeeks
July 11, 2025 - The json_decode() function is an inbuilt function in PHP which is used to decode a JSON string. It converts a JSON encoded string into a PHP variable.
Find elsewhere
🌐
PHP.Watch
php.watch › codex › json_decode
json_decode Function • PHP.Watch
Function • Params and return types changed in PHP 8.0 · Decodes a JSON string.
🌐
Coddy.Tech
coddy.tech › docs › php › json_decode()
PHP json_decode(): Parse JSON into Arrays or Objects | Coddy
3 weeks ago - Decode once, then walk it with ... "Grace", "email": "grace@example.com", "roles": ["editor"]} ] } JSON; $data = json_decode($json, true); foreach ($data['users'] as $user) { $email = $user['email'] ??...
🌐
OnlinePHP
onlinephp.io › json-decode
json_decode - Online Tool
PHP Functions · General · json_decode · Execute json_decode with this online tool json_decode() - Decodes a JSON string · Json Decode Online Tool · Manual · Code Examples · Json Decode Online Tool · Manual · Code Examples · hex2bin ...
🌐
Scaler
scaler.com › home › topics › php json_decode() function
PHP json_decode() Function - Scaler Topics
September 22, 2023 - The json_decode() function in PHP is used to decode a JSON string and convert the JSON data into a corresponding PHP data structure. This allows developers to access and manipulate the data contained within the JSON format using PHP's array and object constructs.
🌐
Nette Blog
blog.nette.org › en › how-to-encode-and-decode-json-in-php
How to encode and decode JSON in PHP? – Nette Blog
August 17, 2026 - (Fixed in PHP 5.3.7) json_decode() returns null if the JSON cannot be decoded or if the encoded data is deeper than the recursion limit. Ok, but json_encode('null') return null too. So we have the same return value for success and failure.
🌐
SitePoint
sitepoint.com › php
Encoding/Decoding JSON PHP - PHP - SitePoint Forums | Web Development & Design Community
February 19, 2023 - I can do this with Javascript, so needing to be schooled in PHP on how to do this. Please help. ... Just replace the backslash double quotes by double quotes and decode it. $data = json_decode(str_replace(‘\"’, ‘"’, $source));
🌐
YouTube
youtube.com › dave hollingworth
Parse JSON in PHP | How to validate and process nested JSON data - YouTube
Learn what JSON is, and how to process it in PHP.Please consider supporting my channel: ☕ https://ko-fi.com/davehollingworthTopics covered:• JSON• Parsing an...
Published: February 19, 2024
Views: 2K
🌐
Envato Tuts+
code.tutsplus.com › home › cloud & hosting
How to Parse JSON in PHP | Envato Tuts+
May 31, 2021 - First, you need to get the data from the file into a variable by using file_get_contents(). Once the data is in a string, you can call the json_decode() function to extract information from the string.
🌐
W3Schools
w3schools.com › php › php_json.asp
PHP and JSON
The json_decode() function returns an object by default.
🌐
Reddit
reddit.com › r/phphelp › json_decode returns null and i don't understand why
r/PHPhelp on Reddit: json_decode returns NULL and I don't understand why
April 26, 2024 -

I have a json_files.php file where I'm placing several JSON objects. One of them is the following:

$jsonGreetingsListEnglish = '{
    "1": "Hello",
    "2": "Hi there",
    "3": "Morning",
    "4": "Evening",
    "5": "Hey",
    "6": "Howdy",
    "7": "Hiya",
    "8": "Welcome",
    "9": "Hi",
    "10": "Yo!",
    "11": "Sup?"
    "12": "Nice"
    "13": "What up?"
    "14": "Aloha"
    "15": "Oi!",
    "16": "Ahoy!",
    "17": "Cheers"
    "18": "Alright?",
    "19": "Hey yo!",
    "20": "Good day"
}';

On a second file I'm decoding it:

include_once "json_files.php";
$greetingsListEnglish = json_decode($jsonGreetingsListEnglish, true);

Later in the same (second) file, I declared this function:

/* Chooses random greeting and encodes it
Retains unencoded greeting for output */
function generateEnglishGreeting() {
    global $greetingsListEnglish;
    $index = array_rand($greetingsListEnglish);
    $unencodedGreeting = $greetingsListEnglish[$index];
    $encodedGreeting = mb_convert_encoding($unencodedGreeting, "UTF-16LE");
    return [$unencodedGreeting, $encodedGreeting];
}

However, when I called this function I get an error that says the decoded array is empty:

Fatal error: Uncaught TypeError: array_rand(): Argument #1 ($array) must be of type array, null given in
C:\xampp\htdocs\join_avenue_visitor_generator\visitor_data_functions.php:88 Stack trace: #0

I ran this to check and when the script runs it always prints "Empty":

if (!empty($greetingsListEnglish)) {
    echo "Not empty";
} else {
    echo "Empty";
}

Am I messing up some syntax or something?

Update: As mentioned in several replies, there were several commas missing. Thanks for all the extra advice.

🌐
Medium
medium.com › techtrends-digest › beyond-json-decode-advanced-php-tricks-for-json-3f0befe1574d
🚀 Beyond json_decode(): Advanced PHP Tricks for JSON 🧠
April 21, 2025 - Normally, json_decode() silently fails. 🤫 But PHP 7.3+ introduced a game-changer: exceptions!
🌐
YouTube
youtube.com › watch
PHP JSON Basics: Master json_encode() & json_decode() - YouTube
Ready to dive into JSON with PHP? In this video, we’ll cover the basics of json_encode() andjson_decode() — two essential functions for converting between PH...
Published: July 23, 2025