Module: Mayak::Json

Extended by:
T::Sig
Defined in:
lib/mayak/json.rb,
lib/mayak/json/encoder.rb

Defined Under Namespace

Modules: Encoder Classes: ParsingError

Constant Summary collapse

JsonType =
T.type_alias {
  T.any(
    T::Array[T.untyped],
    T::Hash[T.untyped, T.untyped],
    String,
    Integer,
    Float
  )
}

Class Method Summary collapse

Class Method Details

.dump(obj) ⇒ Object



24
25
26
# File 'lib/mayak/json.rb', line 24

def self.dump(obj)
  JSON.dump(obj)
end

.parse(string) ⇒ Object



29
30
31
32
33
# File 'lib/mayak/json.rb', line 29

def self.parse(string)
  Mayak::Monads::Try::Success.new(JSON.parse(string))
rescue JSON::ParserError => e
  Mayak::Monads::Try::Failure.new(ParsingError.new(e.message))
end

.parse_unsafe!(string) ⇒ Object



36
37
38
# File 'lib/mayak/json.rb', line 36

def self.parse_unsafe!(string)
  JSON.parse(string)
end