Sha256: 97658829982dc6526c906d932ad83287c6ee336eede60d5508f5da98b04092bd

Contents?: true

Size: 865 Bytes

Versions: 256

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module Appsignal
  module Utils
    # @api private
    class JSON
      class << self
        def generate(body)
          ::JSON.generate(jsonify(body))
        end

        private

        def jsonify(value)
          case value
          when String
            encode_utf8(value)
          when Numeric, NilClass, TrueClass, FalseClass
            value
          when Hash
            value.each_with_object({}) do |(k, v), hash|
              hash[jsonify(k)] = jsonify(v)
            end
          when Array
            value.map { |v| jsonify(v) }
          else
            jsonify(value.to_s)
          end
        end

        def encode_utf8(value)
          value.encode(
            "utf-8".freeze,
            :invalid => :replace,
            :undef   => :replace
          )
        end
      end
    end
  end
end

Version data entries

256 entries across 256 versions & 1 rubygems

Version Path
appsignal-3.3.11-java lib/appsignal/utils/json.rb
appsignal-3.3.11 lib/appsignal/utils/json.rb
appsignal-3.4.0-java lib/appsignal/utils/json.rb
appsignal-3.4.0 lib/appsignal/utils/json.rb
appsignal-3.3.10-java lib/appsignal/utils/json.rb
appsignal-3.3.10 lib/appsignal/utils/json.rb
appsignal-3.3.9-java lib/appsignal/utils/json.rb
appsignal-3.3.9 lib/appsignal/utils/json.rb
appsignal-3.3.8-java lib/appsignal/utils/json.rb
appsignal-3.3.8 lib/appsignal/utils/json.rb
appsignal-3.3.7-java lib/appsignal/utils/json.rb
appsignal-3.3.7 lib/appsignal/utils/json.rb
appsignal-3.3.6-java lib/appsignal/utils/json.rb
appsignal-3.3.6 lib/appsignal/utils/json.rb
appsignal-3.3.5-java lib/appsignal/utils/json.rb
appsignal-3.3.5 lib/appsignal/utils/json.rb
appsignal-3.3.4-java lib/appsignal/utils/json.rb
appsignal-3.3.4 lib/appsignal/utils/json.rb
appsignal-3.3.3-java lib/appsignal/utils/json.rb
appsignal-3.3.3 lib/appsignal/utils/json.rb