<commit_before><?php

class Feediron_Json{
	private static $json_error;
	public static function format($json){
		$result      = '';
		$pos         = 0;
		$strLen      = strlen($json);
		$indentStr   = '    ';
		$newLine     = "\n";
		$prevChar    = '';
		$outOfQuotes = true;
		$currentline = 0;
		$possible_errors = array (
			',]' => 'Additional comma before ] (%s)',
			'""' => 'Missing seperator between after " (%s)',
			',}' => 'Additional comma before } (%s)',
			',:' => 'Comma before :(%s)',
			']:' => '] before :(%s)',
			'}:' => '} before :(%s)',
			'[:' => '[ before :(%s)',
			'{:' => '{ before :(%s)',
		);

		for ($i=0; $i<=$strLen; $i++) {

			// Grab the next character in the string.
			$char = substr($json, $i, 1);
			if($char == $newLine){
				$currentline++;
				continue;
			}
			if($char == ' ' && $outOfQuotes){
				continue;
			}

			if (array_key_exists($prevChar.$char, $possible_errors)){
				self::$json_error = sprintf($possible_errors[$prevChar.$char]. ' in line %s', substr($result, self::strrpos_count($result,$newLine,3)), $currentline);
			}
			// Are we inside a quoted string?
			if ($char == '"' && $prevChar != '\\') {
				$outOfQuotes = !$outOfQuotes;

				// If this character is the end of an element,
				// output a new line and indent the next line.
			} else if(($char == '}' || $char == ']') && $outOfQuotes) {
				$result .= $newLine;
				$pos --;
				for ($j=0; $j<$pos; $j++) {
					$result .= $indentStr;
				}
			}

			// Add the character to the result string.
			$result .= $char;

			// If the last character was the beginning of an element,
			// output a new line and indent the next line.
			if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
				$result .= $newLine;
				if ($char == '{' || $char == '[') {
					$pos ++;
				}

				for ($j = 0; $j < $pos; $j++) {
					$result .= $indentStr;
				}
			}
			else if($char == ':' && $outOfQuotes){
				$result .= ' ';
			}

			$prevChar = $char;
		}

		return $result;
	}
	private static function strrpos_count($haystack, $needle, $count)
	{
		if($count <= 0)
			return false;

		$len = strlen($haystack);
		$pos = $len;

		for($i = 0; $i < $count && $pos; $i++)
			$pos = strrpos($haystack, $needle, $pos - $len - 1);

		return $pos;
	}
	public static function get_error(){
		return self::$json_error;
	}
}
<commit_msg>Replaces JSON format function (#67)<commit_after><?php

class Feediron_Json{
	private static $json_error;
	public static function format($json){
		return json_encode(json_decode($json), JSON_PRETTY_PRINT);
	}
	private static function strrpos_count($haystack, $needle, $count)
	{
		if($count <= 0)
			return false;

		$len = strlen($haystack);
		$pos = $len;

		for($i = 0; $i < $count && $pos; $i++)
			$pos = strrpos($haystack, $needle, $pos - $len - 1);

		return $pos;
	}
	public static function get_error(){
		return self::$json_error;
	}
}

{'fraction_non_alphanumeric': 0.21058091286307054, 'fraction_numerical': 0.005186721991701245, 'mean_word_length': 2.914749661705007, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, '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': '6548521', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1050, 'n_words': 264}