<commit_before>module JSON
  %x{
    var $parse  = JSON.parse,
        $hasOwn = Opal.hasOwnProperty;

    function to_opal(value, options) {
      switch (typeof value) {
        case 'string':
          return value;

        case 'number':
          return value;

        case 'boolean':
          return !!value;

        case 'null':
          return nil;

        case 'object':
          if (!value) return nil;

          if (value.$$is_array) {
            var arr = #{`options.array_class`.new};

            for (var i = 0, ii = value.length; i < ii; i++) {
              #{`arr`.push(`to_opal(value[i], options)`)};
            }

            return arr;
          }
          else {
            var hash = #{`options.object_class`.new};

            for (var k in value) {
              if ($hasOwn.call(value, k)) {
                #{`hash`[`k`] = `to_opal(value[k], options)`};
              }
            }

            var klass;
            if ((klass = #{`hash`[JSON.create_id]}) != nil) {
              klass = Opal.get(klass);
              return #{`klass`.json_create(`hash`)};
            }
            else {
              return hash;
            }
          }
      }
    };
  }

  class << self
    attr_accessor :create_id
  end

  self.create_id = :json_class

  def self.[](value, options = {})
    if String === value
      parse(value, options)
    else
      generate(value, options)
    end
  end

  def self.parse(source, options = {})
    from_object(`$parse(source)`, options)
  end

  def self.parse!(source, options = {})
    parse(source, options)
  end<commit_msg>Fix JSON.load and JSON.parse diverging semantics<commit_after>module JSON
  %x{
    var $parse  = JSON.parse,
        $hasOwn = Opal.hasOwnProperty,
        klass, arr, hash, i, k;

    function to_opal(value, options) {
      switch (typeof value) {
        case 'string':
          return value;

        case 'number':
          return value;

        case 'boolean':
          return !!value;

        case 'null':
          return nil;

        case 'object':
          if (!value) return nil;

          if (value.$$is_array) {
            arr = #{`options.array_class`.new};

            for (i = 0, ii = value.length; i < ii; i++) {
              #{`arr`.push(`to_opal(value[i], options)`)};
            }

            return arr;
          }
          else {
            hash = #{`options.object_class`.new};

            for (k in value) {
              if ($hasOwn.call(value, k)) {
                #{`hash`[`k`] = `to_opal(value[k], options)`};
              }
            }

            if (!options.parse && (klass = #{`hash`[JSON.create_id]}) != nil) {
              klass = Opal.get(klass);
              return #{`klass`.json_create(`hash`)};
            }
            else {
              return hash;
            }
          }
        }
    };
  }

  class << self
    attr_accessor :create_id
  end

  self.create_id = :json_class

  def self.[](value, options = {})
    if String === value
      parse(value, options)
    else
      generate(value, options)
    end
  end

  def self.parse(source, options = {})
    from_object(`$parse(source)`, options.merge(parse: true))
  end

  def self.parse!(source, options = {})
    parse(source, options)
  end

  def self.load(source, options = {})
    from_object(`$parse(source)`, options)
  end
{'fraction_non_alphanumeric': 0.14158504007123776, 'fraction_numerical': 0.0005936479667557139, 'mean_word_length': 1.541478129713424, 'pattern_counts': {'":': 0, '<': 9, '<?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': '56261', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1028, 'n_words': 239}