Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
 hash keys suitable for use with a JSON API.
430122
def to_camelback_keys(value = self)
      case value
      when Array
        value.map { |v| to_camelback_keys(v) }
      when Hash
        Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
      else
        value
      end
    end
46810
def flatten_nested_hash(hash_table):
    
    def flatten(hash_table, brackets=True):
        f = {}
        for key, value in hash_table.items():
            _key = '[' + str(key) + ']' if brackets else str(key)
            if isinstance(value, dict):
                for k, v in flatten(value).items():
                    f[_key + k] = v
            elif isinstance(value, list):
                temp_hash = {}
                for i, v in enumerate(value):
                    temp_hash[str(i)] = v
                for k, v in flatten(temp_hash).items():
                    f[_key + k] = v
            else:
                f[_key] = value
        return f
    return flatten(hash_table, False)
145306
def convert_camel_case_keys(original_dict: Dict[str, Any]) -> Dict[str, Any]:
    """"""
    new_dict = dict()
    for key, val in original_dict.items():
        if isinstance(val, dict):
            # Recurse
            new_dict[convert_camel_case_string(key)] = convert_camel_case_keys(val)
        else:
            new_dict[convert_camel_case_string(key)] = val
    return new_dict
990704
def to_hash
            index_hash = Hash.new
            index_hash["json_claz"] = self.class.name
            index_hash["id"] = id
            index_hash["provider_id"] = provider_id
            index_hash["account_id"] = account_id
            index_hash["provider_name"] = provider_name
            index_hash["options"] = options
            index_hash["created_at"] = created_at
            index_hash
        end
567918
def ToJson(self):
        
        json = {}
        json["hash"] = self.Hash.To0xString()
        json["size"] = self.Size()
        json["version"] = self.Version
        json["previousblockhash"] = self.PrevHash.To0xString()
        json["merkleroot"] = self.MerkleRoot.To0xString()
        json["time"] = self.Timestamp
        json["index"] = self.Index
        nonce = bytearray(self.ConsensusData.to_bytes(8, 'little'))
        nonce.reverse()
        json["nonce"] = nonce.hex()
        json['nextconsensus'] = Crypto.ToAddress(self.NextConsensus)
        # json["consensus data"] = self.ConsensusData
        json["script"] = '' if not self.Script else self.Script.ToJson()
        return json
865773
def hash_from(sym)
      starting_sym = key_as_sym(sym)
      bundle = ((starting_sym == container) ? container : { starting_sym => container[starting_sym] })
      bundle.keys.each_with_object({}) do |attr,collector|
        value = bundle[attr]
        case value
          when NestedResult, self.class
            value = value.to_hash
          when Array
            value = value.map {|ele| array_to_hash(ele) }
        end
        collector[attr] = value                                                          # new copy
      end
    end
732376
private static String camelToSnake(String camel) {
		return CAMEL_TO_SNAKE_PATTERN.matcher(camel).replaceAll("$1_$2").toLowerCase(Locale.US);
	}
526514
def to_hash(options = {})
      out = {}
      each_key do |k|
        assignment_key =
          if options[:stringify_keys]
            k.to_s
          elsif options[:symbolize_keys]
            k.to_s.to_sym
          else
            k
          end
        if self[k].is_a?(Array)
          out[assignment_key] ||= []
          self[k].each do |array_object|
            out[assignment_key] << maybe_convert_to_hash(array_object, options)
          end
        else
          out[assignment_key] = maybe_convert_to_hash(self[k], options)
        end
      end
      out
    end
848593
def to_hash
      attributes.inject({}) do |hash, (key, value)|
        unless Resource::Base.has_attribute?(key)
          hash[Util.camelize(key, true)] = send(key.to_sym)
        end

        hash
      end
    end
864783
def camelcase v
      case
        when v.is_a?(Array)
          v.map {|i| camelcase(i)}
        when v.is_a?(Hash)
          result = {}
          v.each do |k, val|
            result[k.to_s().camelcase(:lower)] = camelcase(val)
          end
          result
        else
          v
      end
    end
1129591
def to_hash(obj=nil, methods:[], recursive: false, check: false, compact: false)
			return {} if obj.nil?
			obj||=self
			stack=[*obj]
			processed=[]
			klass=stack.first.class
			h={}
			while !stack.empty?
				obj=stack.shift
				next if processed.include?(obj)
				processed << obj
				attributes={}
				methods.each do |m|
					next if check and !obj.respond_to? m
					v=obj.public_send(m)
					attributes[m]=v
					if recursive
						vals=v.kind_of?(Enumerable) ? v.to_a.flatten : [v]
						vals.select! {|v| v.kind_of?(klass)}
						stack.concat(vals)
					end
				end
				attributes=attributes.values.first if compact and attributes.keys.length == 1
				h[obj]=attributes
			end
			h
		end
1095318
def to_json_hash
      result = {}

      @values.each_key do |field_name|
        value = self[field_name]
        field = self.class.get_field(field_name, true)

        # NB: to_json_hash_value should come before json_encode so as to handle
        # repeated fields without extra logic.
        hashed_value = if value.respond_to?(:to_json_hash_value)
                         value.to_json_hash_value
                       elsif field.respond_to?(:json_encode)
                         field.json_encode(value)
                       else
                         value
                       end

        result[field.name] = hashed_value
      end

      result
    end
161064
def to_snake_case(camel_case):
  """"""
  if not re.match(r"^[A-Za-z_]\w*$", camel_case):
    raise ValueError(
        "Input string %s is not a valid Python identifier." % camel_case)

  # Add underscore at word start and ends.
  underscored = re.sub(r"([A-Z][a-z])", r"_\1", camel_case)
  underscored = re.sub(r"([a-z])([A-Z])", r"\1_\2", underscored)
  # Add underscore before alphanumeric chunks.
  underscored = re.sub(r"([a-z])([0-9][^_]*)", r"\1_\2", underscored)
  # Remove any underscores at start or end of name and convert to lowercase.
  return underscored.strip("_").lower()
410143
def to_hash
            index_hash = {}
            index_hash['json_claz'] = self.class.name
            index_hash['id'] = id
            index_hash["account_id"] = account_id
            index_hash['name'] = name
            index_hash['allowed'] = allowed
            index_hash['allocated_to'] = allocated_to
            index_hash['quota_type'] = quota_type
            index_hash['status'] = status
            index_hash['inputs'] = inputs
            index_hash['created_at'] = created_at
            index_hash['updated_at'] = updated_at
            index_hash
        end
973023
def snake_case_to_camel_case(value)
      pieces = value.to_s.split '_'

      (pieces.first + pieces[1..-1].map(&:capitalize).join).to_sym
    end
721466
def buffer_key(key, opts)
      # covert keys to strings, as sorting a Hash with Symbol keys fails on
      # Ruby 1.8.x.
      opts = opts.inject({}) do |result, (k, v)|
        result[k.to_s] = v
        result
      end
      "#{key.to_s}:#{opts.sort.flatten.join(':')}"
    end
443566
def jsonhash(obj, root=True, exclude=None, hash_func=_jsonhash_sha1):
    '''
    
    '''
    if isinstance(obj, Mapping):
        # assumption: using in against set() is faster than in against list()
        if root and exclude:
            obj = {k: v for k, v in obj.iteritems() if k not in exclude}
        # frozenset's don't guarantee order; use sorted tuples
        # which means different python interpreters can return
        # back frozensets with different hash values even when
        # the content of the object is exactly the same
        result = sorted(
            (k, jsonhash(v, False)) for k, v in obj.iteritems())
    elif isinstance(obj, list):
        # FIXME: should lists be sorted for consistent hashes?
        # when the object is the same, just different list order?
        result = tuple(jsonhash(e, False) for e in obj)
    else:
        result = obj
    if root:
        result = unicode(hash_func(result))
    return result