PHP JSON decode code is not working

Hello everyone!
I was setting up API docs for my website and I was including example code but I ran into a problem. I wrote some PHP code that was suppost to take an object out of the JSON text and print it.

        <?php
          $api2 = $json_decode(file_get_contents("https://api.riverside.rocks/v1/status"));
          echo $api2[1];
        ?>

This is what the JSON text looks like:

["status: OK","services: OK","API: OK","website: OK","tucker: OK","canary: OK"]
This code did not seem to work for some reason. Any ideas?

Why is there a $ before json_decode?

If the above doesn’t help, please expand on this. What does it do that it should not, or what does it not do that it should? Any error messages? What do you get if you var_dump($api2); ?

1 Like

Removing the $ fixed it. Thank you!
Removing it returns: services: OK

1 Like