Reputation: 4970
I have a JSON file with discrete objects that are not enclosed in another composite object (e.g. an array). The reason for this is that I don't want to rely on the assumption that they will all fit into memory.
In other words, I'd like to iterate over them, reading, parsing, and processing them one at a time.
In YAML I can do this using YAML.load_documents. Is there such a thing in (Ruby) JSON?
Thanks, Keith
Upvotes: 1
Views: 345
Reputation: 37527
So basically you want a streaming parser for JSON.
Try yajl-ruby, a gem with ruby bindings to the Yajl JSON streaming parser library, or JSON::Stream a streaming pure-ruby JSON parser.
Upvotes: 1