Module: Fusion::JsonInput

Defined in:
lib/fusion.rb

Class Method Summary collapse

Class Method Details

.convert(x) ⇒ Object



1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/fusion.rb', line 1131

def self.convert(x)
  case x
  when nil then NULL
  when Array then x.map { |e| convert(e) }
  when Hash then x.each_with_object({}) { |(k, v), h| h[k] = convert(v) }
  else x
  end
end

.parse(text) ⇒ Object

Parse JSON text into Fusion values (null -> NULL).



1123
1124
1125
1126
1127
1128
1129
# File 'lib/fusion.rb', line 1123

def self.parse(text)
  require "json"
  raw = JSON.parse(text)
  convert(raw)
rescue JSON::ParserError
  Fusion.mkerr({"kind" => "stdin_not_json"})
end