Get JSON to print empty array. Get JSON to print empty array. json json

Get JSON to print empty array.


That is because your webserver version must be less than 5.4. You are trying to use a new feature of PHP 5.4 called the short array syntax

Use echo json_encode(array()); instead of echo json_encode( [] );

Working Demo on PHP v 5.3


You have to use this:

if (!empty($output)){        echo json_encode( $output );}        else{            echo json_encode(array());        }


[] for arrays is only supported in php 5.4+.

So that means php is not a high enough version on your host, try asking them to upgrade to 5.4 or try array(); instead of []