$value ) { // Sort the entry alphabetically ksort( $jsonContent["$key"] ); } // Sort the entire file ksort( $jsonContent ); $jsonString = json_encode( $jsonContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); $jsonStringWithTabs = preg_replace_callback( '/^( +)/m', static function ( $matches ) { // Convert spaces to tabs (assuming 4 spaces per tab level) return str_repeat( "\t", strlen( $matches[1] ) / 4 ); }, $jsonString ) . "\n"; // prevent eslint error Unnecessary escape character: \/ no-useless-escape $jsonStringWithTabs = str_replace( '\/', '/', $jsonStringWithTabs ); file_put_contents( $jsonFilePath, $jsonStringWithTabs ); echo "texutil.json successfully sorted.\n"; } } $maintClass = SortTexutil::class; require_once RUN_MAINTENANCE_IF_MAIN;