<commit_before>require "rubygems"
require 'json'
require 'net/http'

module JsonChecker

  class JSONFetcher
  
    def self.json_from_path(path)
      begin
        jsonFile = open(path)
        jsonContent = jsonFile.read
        return JSONFetcher.json_from_content(jsonContent)
      rescue
        puts "[ERROR] #{path} not found"
        return nil
      end
    end
    
    def self.json_from_url(url)
      begin
        uri = URI(url)
        response = Net::HTTP.get_response(uri)
        case response
          when Net::HTTPSuccess then
          return JSONFetcher.json_from_content(response.body)
        else
          puts"[ERROR] Connection error"
        end  
      rescue
      end
      
      return nil
    end
    
    def self.json_from_content(content)
      if content.nil?
        return nil
      end

      begin
        return JSON.parse(content)
      rescue JSON::ParserError => e
        puts "[ERROR] Invalid json"
      end
      return nil
    end
  end
end<commit_msg>Checking if content is a string<commit_after>require "rubygems"
require 'json'
require 'net/http'

module JsonChecker

  class JSONFetcher
  
    def self.json_from_path(path)
      begin
        jsonFile = open(path)
        jsonContent = jsonFile.read
        return JSONFetcher.json_from_content(jsonContent)
      rescue
        puts "[ERROR] #{path} not found"
        return nil
      end
    end
    
    def self.json_from_url(url)
      begin
        uri = URI(url)
        response = Net::HTTP.get_response(uri)
        case response
          when Net::HTTPSuccess then
          return JSONFetcher.json_from_content(response.body)
        else
          puts"[ERROR] Connection error"
        end  
      rescue
      end
      
      return nil
    end
    
    def self.json_from_content(content)
      if content.nil? || !content.is_a?(String)
        return nil
      end

      begin
        return JSON.parse(content)
      rescue JSON::ParserError => e
        puts "[ERROR] Invalid json"
      end
      return nil
    end
  end
end
{'fraction_non_alphanumeric': 0.06747572815533981, 'fraction_numerical': 0.0, 'mean_word_length': 1.8585298196948683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2247658', 'n_tokens_mistral': 599, 'n_tokens_neox': 617, 'n_words': 157}