Answer the question
In order to leave comments, you need to log in
How to properly generate json file?
Hello! For example, there is such json content
{
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [55.831903, 37.411961]
}
}
]
}
$json = json_decode(file_get_contents('data.json'), true);
$json['features'][] = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [55.831903,37.411961]
],
];
file_put_contents('data.json', json_encode($json));
{
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [55.831903, 37.411961]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [65.831903, 47.411961]
}
}
]
}
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [55.831903, 37.411961]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [65.831903, 47.411961]
}
}
]
}
Answer the question
In order to leave comments, you need to log in
Are you kidding me? Learn the basics
$json['type'] = 'asdasdasd';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question