I have a huge JSON file that grows every minute. If every data was added using \n
at the end, it would be really easy to read the file using many upvoted answers here in SO. However, my JSON file has no line ending character, the data is stored like this:
[{a:1,b:"test{}ing"},{a:4,b:"aga,in"},{a:6,b:"another test with \" character"},...]
I want to read, for example, the last 100 entries {}
of this file (which are always appended to the file) and while reading, I want to perform a check on the a
value, if it gets bigger than a specified number OR if reached 100 entries, stop reading the file and output the json object.
How can I do this using PHP? I mean, how can I read the contents at the end of the file and, while reading, parsing the JSON of the content. I have no idea how to do this cause how can I know I can parse the JSON content if it may still be incomplete/malformed?