<commit_before>require 'json'

module JSON
  class << self
    @@loop = 0

    def sorted_generate(obj)
      case obj
        when NilClass, :undef, Fixnum, Float, TrueClass, FalseClass, String
          return simple_generate(obj)
        when Array
          arrayRet = []
          obj.each do |a|
            arrayRet.push(sorted_generate(a))
          end
          return "[" << arrayRet.join(',') << "]";
        when Hash
          ret = []
          obj.keys.sort.each do |k|
            ret.push(k.to_json << ":" << sorted_generate(obj[k]))
          end
          return "{" << ret.join(",") << "}";
        else
          raise Exception.new("Unable to handle object of type #{obj.class.name} with value #{obj.inspect}")
      end
    end

    def sorted_pretty_generate(obj, indent_len=4)

      # Indent length
      indent = " " * indent_len

      case obj
        when NilClass,Fixnum, Float, TrueClass, FalseClass,String
          return simple_generate(obj)<commit_msg>Catch :undef when pretty-printing in consul_sorted_json.rb<commit_after>require 'json'

module JSON
  class << self
    @@loop = 0

    def sorted_generate(obj)
      case obj
        when NilClass, :undef, Fixnum, Float, TrueClass, FalseClass, String
          return simple_generate(obj)
        when Array
          arrayRet = []
          obj.each do |a|
            arrayRet.push(sorted_generate(a))
          end
          return "[" << arrayRet.join(',') << "]";
        when Hash
          ret = []
          obj.keys.sort.each do |k|
            ret.push(k.to_json << ":" << sorted_generate(obj[k]))
          end
          return "{" << ret.join(",") << "}";
        else
          raise Exception.new("Unable to handle object of type #{obj.class.name} with value #{obj.inspect}")
      end
    end

    def sorted_pretty_generate(obj, indent_len=4)

      # Indent length
      indent = " " * indent_len

      case obj
        when NilClass, :undef, Fixnum, Float, TrueClass, FalseClass, String
          return simple_generate(obj)
{'fraction_non_alphanumeric': 0.11952779144121987, 'fraction_numerical': 0.001967535661583866, 'mean_word_length': 1.995581737849779, 'pattern_counts': {'":': 2, '<': 31, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2134493', 'n_tokens_mistral': 614, 'n_tokens_neox': 598, 'n_words': 153}