<commit_before><?php
class utils {
    function json_decode_file($file) {
    	return json_decode(file_get_contents("{$file}"));
	}
    function toObject($array) {
    	$obj = new stdClass();
		foreach ($array as $key => $val)
			$obj->$key = is_array($val) ? self::toObject($val) : $val;
		return $obj;
	}
	function toArray($d) {
		if(is_object($d))
			$d = get_object_vars($d);
		if(is_array($d))
			return array_map(__FUNCTION__, $d);
		else
			return $d;
	}
}<commit_msg>Add json_encode_file() and is_json() for simplifing the json management. Add usenslargs() function to set-up url args separated with ; instend of &<commit_after><?php
class utils {
    function is_json($json) {
        if(substr($json, 0, 1) != "{" && substr($json, 0, 1) != "[" && substr($json, -1) != "}" && substr($json, -1) != "]")
            return false;
        $json = json_decode($json);
        return json_last_error() == JSON_ERROR_NONE;
    }
    function json_decode_file($file) {
    	return json_decode(file_get_contents("{$file}"));
	}
    function usenslargs() {
        ini_set('arg_separator.output',';');
    }
    function json_encode_file($file, $contents) {
        if(!$this->is_json($contents))
            return file_put_contents($file, json_encode($contents));
        return file_put_contents($file, $contents);
    }
	function toObject($array) {
		$obj = new stdClass();
		foreach ($array as $key => $val)
			$obj->$key = is_array($val) ? self::toObject($val) : $val;
		return $obj;
	}
	function toArray($d) {
		if(is_object($d))
			$d = get_object_vars($d);
		if(is_array($d))
			return array_map(__FUNCTION__, $d);
		else
			return $d;
	}
}
{'fraction_non_alphanumeric': 0.17647058823529413, 'fraction_numerical': 0.0036385688295936932, 'mean_word_length': 3.647887323943662, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4579242', 'n_tokens_mistral': 615, 'n_tokens_neox': 584, 'n_words': 122}