Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

JSON::ResumableParser#empty?

empty?

Returns whether the parser is entirely done: no unconsumed bytes in the buffer, no document under construction and no parsed value awaiting retrieval.

The main use case is detecting a truncated stream once the input is exhausted:

Example
loop do
  begin
    parser << socket.readpartial(4096)
  rescue EOFError
    break
  end
  while parser.parse
    process(parser.value)
  end
end
warn "stream was truncated" unless parser.empty?
See also #clear #eos? #<< #parse