I am trying to use PHP to generate JSON to specifically take a desired shape.
Below is a snippet of my PHP code:
if($con){
$sql="select * from people";
$result=mysqli_query($con,$sql);
if($result){
header("Content-Type: JSON");
$i=0;
while($row = mysqli_fetch_assoc($result)){
$response[$i]['gender']=$row['gender'];
$response[$i]['first']=$row['first'];
$i++;
}
echo json_encode($response, JSON_PRETTY_PRINT);
}
}
Here is my current JSON response
[
{
"gender":"male",
"first":"Angela"
},
{
"gender":"female",
"first":"Krista"
}
]
And here is my desired response:
{
"inputs": [
{
"values": {
"gender": "male",
"first": "Angela"
}
},
{
"values": {
"gender": "female",
"first": "Krista"
}
}
]
}