Module: TrajectPlus::Macros::JSON

Defined in:
lib/traject_plus/macros/json.rb

Overview

Macros for extracting values from JSON documents

Instance Method Summary collapse

Instance Method Details

#extract_json(path, options = {}) ⇒ Object

Parameters:

  • path (String)

    the jsonpath query expression

  • options (Hash) (defaults to: {})

    other options, may include :trim



11
12
13
14
15
16
17
18
19
20
# File 'lib/traject_plus/macros/json.rb', line 11

def extract_json(path, options = {})
  lambda do |json, accumulator, _context|
    result = Array(JsonPath.on(json, path))
    result = TrajectPlus::Extraction.apply_extraction_options(result, options)
    unless options.empty?
      Deprecation.warn(self, "passing options to extract_json is deprecated and will be removed in the next major release. Use the Traject 3 pipeline instead")
    end
    accumulator.concat(result)
  end
end