Stateful JSON Parser for Ruby

321 Views Asked by At

I have a Ruby server that reads from a flat file every 1 second or so and this flat file is constantly being updated with new data every 1 second or so by another server. This flat file is essentially a JSON file. The thing is, I don't wanna read the entire file over and over again. Rather, I want the ruby server to figure out which of the content is new and read only those portions. So I'm guessing I'm searching for a stateful JSON parser for Ruby. Since I'm very new to Ruby, I'm not familiar with such a library. Could anybody suggest something that might work in such a situation?

1

There are 1 best solutions below

4
On

There's no such thing as "stateful JSON parser". Stateful (as in "stateful server") means that server (or parser) maintains some state between requests (parsings). But you'll have to read and parse the whole file anyway, so why complicate stuff?

If the file is small, just parse it whole every time. If the file is ginormous, use a database instead.