I have the next json:
[
{
"clave": "es",
"content": {
"barra": [
"a",
"a",
"N",
"C"
],
"letras_inicio": "a",
"titulos_servicios": [
"A",
"A",
"A"
],
"desc_servicios": [
"O",
"O",
"E"
],
"titulo_nosotros": "n",
"descripcion_nosotros": "S",
"titulos_especialidades": [
"A",
"A"
],
"desc_especialidades": [
"E",
"L"
],
"titulo_frm_contacto": "Co",
"frmContacto": [
"N",
"c",
"C",
"A",
"M",
"E"
]
}
},
{
"clave": "por",
"content": {
"barra": [
"f",
"f",
"f",
"f"
],
"letras_inicio": "f",
"titulos_servicios": [
"f",
"f",
"f"
],
"desc_servicios": [
"qf",
"qf",
"qf"
],
"titulo_nosotros": "f",
"descripcion_nosotros": "qf",
"titulos_especialidades": [
"f",
"f"
],
"desc_especialidades": [
"qf",
"qf"
],
"titulo_frm_contacto": "f",
"frmContacto": [
"f",
"f",
"f",
"f",
"f",
"f"
]
}
}
]
The next code is that i use to delete a node from json file:
$json = file_get_contents('php://input');
$obj = json_decode($json);
$index = filter_var($obj->index);
$data = file_get_contents('languajes.json');
$data = json_decode($data,true);
unset($data[$index]);
if($data = json_encode($data,JSON_PRETTY_PRINT)){
echo 'success';
}else{
echo 'failed';
}
file_put_contents('languajes.json', $data);
So, when I save the json it looks like:
{
"0": {
"clave": "es",
"content": {
"barra": [
"I",
"S",
"N",
"C"
],
"letras_inicio": "N",
"titulos_servicios": [
"A",
"A",
"A"
],
"desc_servicios": [
"O",
"O",
"E"
],
"titulo_nosotros": "N",
"descripcion_nosotros": "S",
"titulos_especialidades": [
"A",
"A"
],
"desc_especialidades": [
"E",
"L"
],
"titulo_frm_contacto": "C",
"frmContacto": [
"N",
"A",
"C",
"A",
"M",
"E"
]
}
},
"2": {
"clave": "en",
"content": {
"barra": [
"H",
"S",
"A",
"C"
],
"letras_inicio": "W",
"titulos_servicios": [
"W",
"M",
"D"
],
"desc_servicios": [
"W",
"W",
"W"
],
"titulo_nosotros": "A",
"descripcion_nosotros": "W",
"titulos_especialidades": [
"W",
"m"
],
"desc_especialidades": [
"f",
"a"
],
"titulo_frm_contacto": "C",
"frmContacto": [
"F",
"L",
"E",
"S",
"M",
"S"
]
}
}
}
The problem is when y try to read the data after save the data in json file, the number that php put it causes that I can't read the file. how can I avoid that this happen?
I will be to grateful for your answers
file_put_contents('languajes.json', array_values($data));