I want to Convert the JSON file to key:value pair, means
[
{"value":"apple","label":"apple"},
{"value":"Google","label":"Google"}
]
Like below key:value pair format, like this
{
"apple": "apple",
"google": "google",
.......
.....
......
......
}
So any one can tell me how can i do so, below is the Php file code, in which i have taken the data from the psql database and storing it in a file .
dbconn.php
<?php
$db = pg_connect("host=localhost port=5432 dbname=postgres user=postgres password=root123");
pg_select($db, 'post_log', $_POST); //selecting database
$query=pg_query("SELECT name FROM account");
$json=array();
while($student=pg_fetch_array($query)){
$json[]=array(
'value'=> $student["name"],
'label'=>$student["name"]);
}
$textval = json_encode($json); //encoding
file_put_contents('textvalues.txt', $textval);
?>