class JsonSlide::Parser

Parser

Public Class Methods

parse(json_input) click to toggle source
# File lib/json_slide/parser.rb, line 23
def parse(json_input)
  begin
    json = if(json_input =~ URI::regexp)
      RestClient.get(json_input)
    elsif ( !(json_input).match(/\.json$/i).nil? && File.exist?(json_input) && File.file?(json_input) )
      File.read(json_input)
    else
      json_input
    end
    JSON.parse(json, { symbolize_names: true })
  rescue JSON::ParserError
    raise "Invalid JSON Format!! Please enter a valid json string or json file with path or json file url."
  rescue URI::InvalidURIError
    raise "Invalid JSON url!! Please enter a valid json string or json file with path or json file url."
  rescue => e
    raise e.message
  end
end