data_importer/lib/json_helper.rb

21 lines
445 B
Ruby
Raw Normal View History

2022-04-19 02:37:27 -05:00
# frozen_string_literal: true
2022-04-19 02:37:27 -05:00
class JsonHelper
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) }
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 }
end
2022-04-20 00:15:01 -05:00
def self.fix_null_byte(s)
s.gsub("`\u0000`", "null_byte")
end
end