def encode(table)
      table.each_with_object(table.dup) do |(k1, v1), accu|
        v1.each do |k2, v2|
          if v2.is_a?(Rational)
            accu[k1][k2] = { "numerator" => v2.numerator, "denominator" => v2.denominator }
          end
        end
      end
    end
def encode(table)
      table.each_with_object(table.dup) do |(k1, v1), accu|
        v1.each do |k2, v2|
          if v2.is_a?(Rational)
            accu[k1][k2] = { "numerator" => v2.numerator, "denominator" => v2.denominator }
          end
        end
      end
    end
JSON dump and load of Rational objects exists, but it changes the behaviour of JSON globally if required.
 Instead, the same marshalling technique is rewritten here to prevent changing this behaviour project wide.
 https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/add/rational.rb