travis-ci/travis-core · formats.rb
ruby logo
def normalize_json(json)
      json = json.to_json unless json.is_a?(String)
      JSON.parse(json)
    end
Similar code snippets
1.
rsinger/RDFObjects · parsers.rb
Match rating: 74.3% · 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
2.
hidroh/cucumber-api · response.rb
Match rating: 68.17% · 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
3.
bilus/kawaii · formats.rb
Match rating: 62.92% · 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
4.
hidroh/cucumber-api · response.rb
Match rating: 62.75% · See similar code snippets
ruby logo
def get json_path, json=nil
      if json.nil?
        json = JSON.parse body
      end
      results = JsonPath.new(json_path).on(json)
      if results.empty?
        raise %/Expected json path '#{json_path}' not found\n#{to_json_s}/
      end
      results.first
    end
5.
mwunsch/weary · request.rb
Match rating: 61.85% · See similar code snippets
ruby logo
def json(parameters)
      json = MultiJson.encode(parameters)
      body stringio_encode(json)
      json
    end
6.
wjdhamilton/easy-json-matcher · json_coercer.rb
Match rating: 60.92% · 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
7.
yuroyoro/git-issue · github.rb
Match rating: 60.21% · See similar code snippets
ruby logo
def post_json(url, json, options, params = {})
    response = send_request(url, json, options, params, :post)
    json = JSON.parse(response.body)

    raise error_message(json) unless response_success?(response)
    json
  end
8.
soulim/oembed · parser.rb
Match rating: 59.94% · 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
9.
corespring/corespring-ruby · api_client.rb
Match rating: 59.31% · 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
10.
rogerleite/restfolia · resource_creator.rb
Match rating: 58.87% · See similar code snippets
ruby logo
def create(json)
      if json.is_a?(Array)
        json.inject([]) do |result, json_hash|
          result << create_resource(json_hash)
        end
      elsif json.is_a?(Hash)
        create_resource(json)
      else
        raise(ArgumentError, "JSON parameter have to be a Hash or Array object", caller)
      end
    end