Class: Embulk::Guess::JsonGuessPlugin

Inherits:
Embulk::GuessPlugin show all
Defined in:
lib/embulk/guess/json.rb

Instance Method Summary collapse

Methods inherited from Embulk::GuessPlugin

from_java, new_java

Instance Method Details

#guess(config, sample_buffer) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/embulk/guess/json.rb', line 14

def guess(config, sample_buffer)
  return {} unless config.fetch("parser", {}).fetch("type", "json") == "json"

  # Use org.embulk.spi.json.JsonParser to respond to multi-line Json
  json_parser = new_json_parser(sample_buffer)
  begin
    while json_parser.next
    end
  rescue JsonParseException
    return {}
  end

  return {"parser" => {"type" => "json"}}
end