I have this in my text tile
[{"id":20,"tokenType":"Keyfob","tokenValue":"9037119","isLost":false}][{"id":22,"tokenType":"Keyfob","tokenValue":"47690743","isLost":false}]
But i am trying to convert it to json object like this below:
$cache_file = $_SERVER['DOCUMENT_ROOT']."/site/users/sample-keys-test.txt";
$file = fopen($cache_file, "r");
$file_content = fread($file, filesize($cache_file));
$file_content = preg_replace("/[(.*?)]/", "$1,", $file_content);
$file_content = rtrim($file_content, ",");
$data = json_decode("{"items": [".$file_content."]}", true);
var_dump($data);
foreach($data["items"] as $json_object) {
// Do something with each JSON object
echo $json_object["id"]."<br>";
echo $json_object["tokenType"]."<br>";
echo $json_object["tokenValue"]."<br>";
echo $json_object["isLost"]."<br>";
}
fclose($file);
But in the line with var_dump i get null which means there is something wrong with converting it to json object.