Module: Feroxbuster::Parsers::JSON

Defined in:
lib/feroxbuster/parsers/json.rb

Overview

Parses single-line JSON hashes.

Class Method Summary collapse

Class Method Details

.parse(io) {|data| ... } ⇒ Enumerator

Parses a single-line of JSON.

Parameters:

  • io (IO)

    The IO stream to parse.

Yields:

  • (data)

    The given block will be passed each parsed data.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/feroxbuster/parsers/json.rb', line 29

def self.parse(io)
  return enum_for(__method__,io) unless block_given?

  io.each_line do |line|
    line.chomp!
    json = ::JSON.parse(line)

    case json["type"]
    when "response"
      yield map_response(json)
    when "statistics"
      yield map_statistics(json)
    else
      raise(NotImplementedError,"unsupported JSON type: #{json['type']}")
    end
  end
end