I have a json file in which I am storing array of json objects. I am using 'file_get_contents()' to read data, the data read is in the form of string. I am actually returning the data and in the front-end js fetches json data. But I used json_encode() and returned the data. Even then it is returning a string(in json format) instead of json data. Can anyone help me out
My php code
$response = '[';
$date = date('Y-m-d', strtotime($date));
$file = file_get_contents("uploads/sample.json");
$file = str_split($file, strlen($file)-2)[0];
if ($file === '') {
self::json_respond('', 'Nothing is uploaded on '. date("Y-m-d"));
}
$response .= $file.']';
return json_encode($response);
My json file is
{ "name": "sample.css", "file_path": "uploads/sample.css","date_uploaded": "2018-07-10" }
{ "name": "simple.mp4", "file_path": "uploads/video1.mp4","date_uploaded": "2018-07-10" }
{ "name": "cat.jpeg", "file_path": "uploads/image.jpeg","date_uploaded": "2018-07-11" },
But is is jsut printing a json string when I do console.log(response) instead of printing the data in json