How can I write into existing JSON-file the data from backend-Formular in Typo3 directly? And how can I later delete some data from JSON, when I delete them from the backend in Typo3? All JSON enterings have a time stamp.
Thank you in advance!
as JSON, is not a linear file Format but rather a Serialized object. its not possible to append data to it.
what you have to to is:
1) read the json file
2) use json_decode()
to get an stdObject or array
3) manipulate that data Object/array the way you want.
4) use json_encode()
to convert it back to a string..
5) write it back to a file.
// Load The Data
$pathToYourFile = 'paht/somefile.json';
$dataString = file_get_contents($pathToYourFile);
$jsonDataArray = json_decode($dataString, true); // fetch Data as ArrayM
///Maniuplate the data like you want
$jsonDataArray['someValue'] = 'updated Value';
// write it back
$dataString = json_encode($jsonDataArray);
file_put_contents($dataString);