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#parsed_bytes

parsed_bytes → integer

Returns the number of bytes parsed since the start of the current partial value. This is intended to be used for securing against untrusted input:

Example
loop do
  if parser.parsed_bytes > DOCUMENT_MAX_SIZE
    raise "document too large"
  end

  parser << read_chunk
  while parser.parse
    process(parser.value)
  end
end