require 'legion/json/version' require 'legion/json/parse_error' module Legion # Used to create JSON objects module JSON class << self # Set up the JSON parser. This method must be called before any # attempt to use the parser. This method is currently called at # the bottom of this file. The appropriate JSON parser will be # loaded for the current platform. # # @return [Object] parser. def setup! if RUBY_ENGINE == 'jruby' require 'legion/json/jrjackson' @parser = Legion::JSON::JrJackson.new else require 'legion/json/oj' @parser = Legion::JSON::Oj.new end end # Load (and parse) a JSON string. # # @param string [String] # @return [Object] def load(string) @parser.load(string) rescue StandardError => error raise Legion::JSON::ParseError.build(error, string) end # Dump (generate) a JSON string from a Ruby object. # # @param object [Object] # @param options [Hash] def dump(object, options = {}) @parser.dump(object, options) end end end end Legion::JSON.setup!