Class: LLM::JSONAdapter::JSON

Inherits:
LLM::JSONAdapter show all
Defined in:
lib/llm/json_adapter.rb

Overview

The LLM::JSONAdapter::JSON class provides a JSON adapter backed by the standard library JSON module.

Class Method Summary collapse

Class Method Details

.dump(obj, state = nil, **options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/llm/json_adapter.rb', line 38

def self.dump(obj, state = nil, **options)
  require "json" unless defined?(::JSON)
  if ::JSON::State === state
    ::JSON.generate(obj, state)
  elsif state
    ::JSON.dump(obj, state, **options)
  else
    ::JSON.dump(obj, **options)
  end
end

.load(string) ⇒ Object



51
52
53
54
# File 'lib/llm/json_adapter.rb', line 51

def self.load(string, ...)
  require "json" unless defined?(::JSON)
  ::JSON.parse(string, ...)
end

.parser_errorObject



58
59
60
61
# File 'lib/llm/json_adapter.rb', line 58

def self.parser_error
  require "json" unless defined?(::JSON)
  [::JSON::ParserError]
end