Module: JsonSorter

Defined in:
lib/facetq/json_sorter.rb

Class Method Summary collapse

Class Method Details

.sort_hash(hash) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/facetq/json_sorter.rb', line 3

def self.sort_hash(hash)
  sorted = hash.sort_by { |k, _| [k.length, k] }
  
  sorted.each_with_object({}) do |(key, value), result|
    result[key] = value.is_a?(Hash) ? sort_hash(value) : value
  end
end