def params_sorted_by_key(params)
      case params
      when Hash
        params.map     { |k, v| [k.to_s, params_sorted_by_key(v)] }
              .sort_by { |k, v| k }
              .to_h
      when Array
        params.map { |val| params_sorted_by_key(val) }
      else
        params.to_s
      end
    end
def params_sorted_by_key(params)
      case params
      when Hash
        params.map     { |k, v| [k.to_s, params_sorted_by_key(v)] }
              .sort_by { |k, v| k }
              .to_h
      when Array
        params.map { |val| params_sorted_by_key(val) }
      else
        params.to_s
      end
    end
stringifies and sorts hashes by key at all levels.