Skip to content

[WIP] Add XML to JSON migration tool#171

Closed
Copilot wants to merge 1 commit intomasterfrom
copilot/add-xml-to-json-migration-tool
Closed

[WIP] Add XML to JSON migration tool#171
Copilot wants to merge 1 commit intomasterfrom
copilot/add-xml-to-json-migration-tool

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>[8] Create XML to JSON Migration Tool</issue_title>
<issue_description>Estimate: 2 days
Sprint: Week 3-4
Assignee: [Developer]


Description

Build a command-line tool to migrate existing XML configuration files to JSON format, using the schemas created in Ticket #7.

Context

  • Users have existing XML configurations
  • Need automated migration to avoid manual conversion
  • Should validate output against JSON schemas

AI Prompt

Create a ConfigMigrationTool console application that:

1. Discovers all XML configuration files in a directory
2. Identifies the schema type of each XML file
3. Converts to equivalent JSON using the POCOs from Ticket intel/acat#7
4. Validates converted JSON against schema
5. Writes JSON files to output directory
6. Generates migration report with:
   - Files processed
   - Successful conversions
   - Errors/warnings
   - Manual review needed

Include:
- Progress bar during migration
- Dry-run mode (preview changes)
- Backup original files
- Rollback capability
- Detailed logging

Use System.CommandLine for CLI interface.

Tasks

  • Create new console project ACAT.ConfigMigrationTool
  • AI generates migration logic
  • Add XML → POCO deserializers
  • Add POCO → JSON serializers
  • Implement validation
  • Add CLI arguments and help
  • Test with real XML files
  • Create user documentation

Acceptance Criteria

  • ✅ Tool successfully converts all test XML files
  • ✅ JSON validates against schemas
  • ✅ No data loss in conversion
  • ✅ Migration report generated
  • ✅ Dry-run mode works
  • ✅ Backup files created
  • ✅ User documentation complete

CLI Interface

# Dry run (preview)
ConfigMigrationTool.exe migrate --input "C:\ACAT\Config" --dry-run

# Actual migration
ConfigMigrationTool.exe migrate --input "C:\ACAT\Config" --output "C:\ACAT\ConfigJson" --backup

# Validate only
ConfigMigrationTool.exe validate --input "C:\ACAT\ConfigJson"

# Rollback
ConfigMigrationTool.exe rollback --backup "C:\ACAT\Config.backup"

Example Implementation

// Program.cs
using System.CommandLine;

var rootCommand = new RootCommand("ACAT Configuration Migration Tool");

var migrateCommand = new Command("migrate", "Migrate XML configs to JSON");
var inputOption = new Option<string>("--input", "Input directory") { IsRequired = true };
var outputOption = new Option<string>("--output", "Output directory") { IsRequired = true };
var dryRunOption = new Option<bool>("--dry-run", "Preview changes without applying");
var backupOption = new Option<bool>("--backup", "Backup original files");

migrateCommand.AddOption(inputOption);
migrateCommand.AddOption(outputOption);
migrateCommand.AddOption(dryRunOption);
migrateCommand.AddOption(backupOption);

migrateCommand.SetHandler(async (string input, string output, bool dryRun, bool backup) =>
{
    var migrator = new ConfigurationMigrator();
    var result = await migrator.MigrateAsync(input, output, dryRun, backup);
    Console.WriteLine(result.GenerateReport());
}, inputOption, outputOption, dryRunOption, backupOption);

rootCommand.AddCommand(migrateCommand);
await rootCommand.InvokeAsync(args);

// ConfigurationMigrator.cs
public class ConfigurationMigrator
{
    public async Task<MigrationResult> MigrateAsync(
        string inputDir, 
        string outputDir, 
        bool dryRun, 
        bool backup)
    {
        var result = new MigrationResult();
        var xmlFiles = Directory.GetFiles(inputDir, "*.xml", SearchOption.AllDirectories);
        
        foreach (var xmlFile in xmlFiles)
        {
            try
            {
                // Detect schema type
                var schemaType = DetectSchemaType(xmlFile);
                
                // Convert XML → POCO → JSON
                var json = ConvertToJson(xmlFile, schemaType);
                
                // Validate
                var isValid = ValidateJson(json, schemaType);
                
                if (!dryRun && isValid)
                {
                    if (backup)
                    {
                        File.Copy(xmlFile, xmlFile + ".backup", true);
                    }
                    
                    var jsonPath = Path.Combine(outputDir, 
                        Path.GetFileNameWithoutExtension(xmlFile) + ".json");
                    await File.WriteAllTextAsync(jsonPath, json);
                }
                
                result.SuccessCount++;
            }
            catch (Exception ex)
            {
                result.Errors.Add((xmlFile, ex.Message));
            }
        }
        
        return result;
    }
}

Testing

# Test with sample files
ConfigMigrationTool.exe migrate --input "...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes intel/acat#159

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants