instructure/ims-lti · lti_model.rb
ruby logo
def from_json(json)
      json = json.to_json unless json.is_a?(String)
      begin
        data = JSON.parse(json)
      rescue
        data = JSON.parse(URI.unescape(json))
      end

      if data.is_a? Array
        data.map { |hash| self.class.from_json(hash.to_json) }
      else
        process_json_hash(data)
      end
    end
Similar code snippets
1.
travis-ci/travis-core · formats.rb
Match rating: 67.76% · See similar code snippets
ruby logo
def normalize_json(json)
      json = json.to_json unless json.is_a?(String)
      JSON.parse(json)
    end
2.
rsinger/RDFObjects · parsers.rb
Match rating: 66.49% · See similar code snippets
ruby logo
def data=(json)
      if json.is_a?(String)
        @json = JSON.parse(json)
      elsif json.is_a?(Hash)
        @json = json
      elsif json.respond_to?(:read)
        @json = JSON.parse(json.read)
      end
    end
3.
bradurani/pg-eyeballs · inspector.rb
Match rating: 61.87% · See similar code snippets
ruby logo
def to_hash_array(options: OPTIONS)
      to_json(options: options).map { |json| JSON.parse(json) }
    end
4.
Katello/katello_api · base.rb
Match rating: 59.96% · See similar code snippets
ruby logo
def process_data(response)
      data = begin
               JSON.parse(response.body)
             rescue JSON::ParserError
               response.body
             end
      return data, response
    end
5.
hidroh/cucumber-api · response.rb
Match rating: 59.13% · See similar code snippets
ruby logo
def has json_path, json=nil
      if json.nil?
        json = JSON.parse body
      end
      not JsonPath.new(json_path).on(json).empty?
    end
6.
soracom/soracom-sdk-ruby · api_client.rb
Match rating: 58.27% · See similar code snippets
ruby logo
def parse(response)
      begin
        return JSON.parse(response)
      rescue JSON::ParserError => e
        return {result: response}
      end
    end
7.
soulim/oembed · parser.rb
Match rating: 58.24% · See similar code snippets
ruby logo
def json(body)
      begin
        JSON.parse(body)
      rescue JSON::JSONError => e
        raise Oembed::ParserError.new(e), 'JSON parser error'
      end
    end
8.
wjdhamilton/easy-json-matcher · json_coercer.rb
Match rating: 57.64% · See similar code snippets
ruby logo
def coerce(json:)
      begin
        JSON.parse(json)
      rescue JSON::ParserError, TypeError
        raise CoercionError.new invalid_string: json
      end
    end
9.
bilus/kawaii · formats.rb
Match rating: 57.27% · See similar code snippets
ruby logo
def parse_params(request)
      json = request.body.read
      JSON.parse(json).symbolize_keys if json.is_a?(String) && !json.empty?
    end
10.
corespring/corespring-ruby · api_client.rb
Match rating: 57.04% · See similar code snippets
ruby logo
def api_response(response, model=nil)
        json = JSON.parse(response.body)
        raise(APIError, json['message'] || json['error'] || json) if response.code != 200

        if model
          model.new(json)
        else
          json
        end
      end