I have json output written in php.
<?php
// parametri del database
$db_host = "<ip-address>";
$db_user = "<database user>";
$db_password = "<database password>";
$db_name = "<database name>";
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri...");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri...");
$q=mysql_query("SELECT * FROM <nome tabella>");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
The "problem" is that is not formatting well but the output is in a single line.
[{"id":"1","Nome":"Pippo","Cognome":"Paperino","mail":"pippo.paperino@disney.com","cell":"3333333333}]
How can i display the output like:
{
"a": "apple",
"b": "banana",
"c": "catnip"
}
?
i tryied using echo json_encode($response, JSON_PRETTY_PRINT);
but doesn't work.. i wrote
print(json_encode($output, JSON_PRETTY_PRINT));
but i get an error.