2022-04-19 02:37:27 -05:00
|
|
|
# frozen_string_literal: true
|
2022-04-18 22:07:22 -05:00
|
|
|
|
2022-04-19 02:37:27 -05:00
|
|
|
class JsonHelper
|
2022-04-18 20:01:57 -05:00
|
|
|
def self.deep_transform_keys(json_hash)
|
|
|
|
if json_hash.is_a? Array
|
2022-04-19 02:37:27 -05:00
|
|
|
json_hash.map { |jh| symbolize_names_snake_case(jh) }
|
2022-04-18 20:01:57 -05:00
|
|
|
else
|
|
|
|
symbolize_names_snake_case(json_hash)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.symbolize_names_snake_case(json_hash)
|
2022-04-19 02:37:27 -05:00
|
|
|
json_hash.deep_transform_keys { |k| k.to_s.underscore.to_sym }
|
2022-04-18 20:01:57 -05:00
|
|
|
end
|
2022-04-20 00:15:01 -05:00
|
|
|
|
|
|
|
def self.fix_null_byte(s)
|
|
|
|
s.gsub("`\u0000`", "null_byte")
|
|
|
|
end
|
|
|
|
|
2022-04-18 20:01:57 -05:00
|
|
|
end
|