My code generates a json file:
<?php
$arr_clientes = array('nombre'=> 'Jose', 'edad'=> '20', 'genero'=> 'masculino',
'email'=> '[email protected]', 'localidad'=> 'Barcelona', 'telefono'=> '91000000');
//Creo el JSON
$json_string = json_encode($arr_clientes);
$file = 'clientes.json';
file_put_contents($file, $json_string);
?>
Then the generated file contains the following:
{"nombre":"Jose","edad":"20","genero":"masculino","email":"[email protected]","localidad":"Barcelona","telefono":"91000000"}
How do I get a file like this?
{
"items": [
{
"nombre": "Jose",
"edad": "20",
"genero": "masculino",
"email": "[email protected]",
"localidad": "Barcelona",
"telefono": "91000000"
},
{
"nombre": "Pedro",
"edad": "24",
"genero": "masculino",
"email": "[email protected]",
"localidad": "Madrid",
"telefono": "92000000"
}
]
}
Thanks in advance.
I hope to help Mariano:
I made a new variable called
$plantillaJson
and made an array with the items element and added the customer array to the element.