def replace_hash_at_path(hash, key, value)
      path = JsonPath.new(key).path
      if !value.nil?
        # REVIEW: Is there a better way to parse the JSON Path and ensure
        # a value at the location?
        (0...(path.length - 1)).each do |i|
          eval("hash#{path[0..i].join('')} ||= {}")
        end
        eval("hash#{path.join('')} = #{value.inspect}")
      elsif JsonPath.new(key).on(hash).count > 0
        # Path value is present, but we need to unset it
        leaf_key = eval(path[-1]).first
        eval("hash#{path[0...-1].join('')}.delete(#{leaf_key.inspect})")
      end

      hash
    end
def replace_hash_at_path(hash, key, value)
      path = JsonPath.new(key).path
      if !value.nil?
        # REVIEW: Is there a better way to parse the JSON Path and ensure
        # a value at the location?
        (0...(path.length - 1)).each do |i|
          eval("hash#{path[0..i].join('')} ||= {}")
        end
        eval("hash#{path.join('')} = #{value.inspect}")
      elsif JsonPath.new(key).on(hash).count > 0
        # Path value is present, but we need to unset it
        leaf_key = eval(path[-1]).first
        eval("hash#{path[0...-1].join('')}.delete(#{leaf_key.inspect})")
      end

      hash
    end
rubocop:disable Eval