function handleFileUpload()

in script.js [466:504]


  function handleFileUpload(event) {
    const file = event.target.files[0];
    if (!file) return;

    const reader = new FileReader();
    reader.onload = function (e) {
      try {
        // Parse JSON
        currentData = JSON.parse(e.target.result);

        // Validate the JSON structure
        if (!currentData.management_groups || !Array.isArray(currentData.management_groups)) {
          throw new Error("Invalid JSON format: missing or invalid 'management_groups' array");
        }

        // Update UI safely
        try {
          // Set architecture name
          architectureNameInput.value = currentData.name || '';

          // Enable download button
          document.getElementById('download-file').disabled = false;

          // Render management groups
          renderManagementGroups();
          updateJsonPreview();
        } catch (renderError) {
          console.error('Error rendering data:', renderError);
          alert('Error rendering data: ' + renderError.message);
        }
      } catch (error) {
        console.error('Error processing JSON file:', error);
        alert('Invalid JSON file: ' + error.message);
        // Reset current data if parsing failed
        currentData = null;
      }
    };
    reader.readAsText(file);
  }