class Praxis::Handlers::JSON

Public Class Methods

new() click to toggle source

Construct a JSON handler and initialize any related libraries.

@raise [Praxis::Exceptions::InvalidConfiguration] if the handler is unsupported

# File lib/praxis/handlers/json.rb, line 7
def initialize
  require 'json'
rescue LoadError
  # Should never happen since JSON is a default gem; might as well be cautious!
  raise Praxis::Exceptions::InvalidConfiguration,
        "JSON handler depends on json ~> 1.0; please add it to your Gemfile"
end

Public Instance Methods

generate(structured_data) click to toggle source

Generate a pretty-printed JSON document from structured data.

@param [Hash,Array] structured_data @return [String]

# File lib/praxis/handlers/json.rb, line 27
def generate(structured_data)
  ::JSON.pretty_generate(structured_data)
end
parse(document) click to toggle source

Parse a JSON document into structured data.

@param [String] document @return [Hash,Array] the structured-data representation of the document

# File lib/praxis/handlers/json.rb, line 19
def parse(document)
  ::JSON.parse(document)
end