new stdClass()], JSON_PRETTY_PRINT); exit; } $categories = array_filter(glob($recipesDir . '/*'), 'is_dir'); $output = ["recipes" => []]; foreach ($categories as $categoryPath) { $categoryName = basename($categoryPath); $items = array_filter(glob($categoryPath . '/*'), 'is_dir'); $itemNames = array_map('basename', $items); if (!empty($itemNames)) { $output["recipes"][$categoryName] = array_values($itemNames); } } echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>