Sha256: 13f160b673e515e9814edd125a1bd58131b3756487873356011834cc253ab084

Contents?: true

Size: 429 Bytes

Versions: 2

Compression:

Stored size: 429 Bytes

Contents

# Add a formatter to grape that converts all snake case hash keys from ruby to camel case.
require 'camel_snake_keys'
module IntrospectiveGrape
  module Formatter
    module CamelJson
      def self.call(object, _env)
        if object.respond_to?(:to_json)
          JSON.parse(object.to_json).with_camel_keys.to_json
        else
          MultiJson.dump(object).with_camel_keys.to_json
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
introspective_grape-0.3.0 lib/introspective_grape/formatter/camel_json.rb
introspective_grape-0.2.9 lib/introspective_grape/formatter/camel_json.rb