Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GroupDocsGists/9a6e1ffeb7cbd9daf2779033d33972da to your computer and use it in GitHub Desktop.

Select an option

Save GroupDocsGists/9a6e1ffeb7cbd9daf2779033d33972da to your computer and use it in GitHub Desktop.
Convert JSON to XML with GroupDocs.Conversion for .NET
using System;
using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Options.Load;
namespace JsonToXmlDemo
{
class Program
{
static void Main(string[] args)
{
// Set up license (use temporary license for testing)
var license = new License();
license.SetLicense("license.lic"); // Path to your license file
// Initialize conversion handler
using (var conversionHandler = new ConversionHandler())
{
try
{
// Load JSON source file
var loadOptions = new LoadOptions { Format = "json" };
var source = conversionHandler.Load("input.json", loadOptions);
// Configure XML conversion options
var convertOptions = new ConvertOptions
{
Format = "xml",
// Advanced options
PreserveAttributes = true, // Keep JSON properties as XML attributes
RootElementName = "Root", // Custom root element name
// You can add custom node mappings here if needed
};
// Perform conversion and save to output file
source.Convert("output.xml", convertOptions);
Console.WriteLine("Conversion completed successfully. Output saved to output.xml");
}
catch (Exception ex)
{
Console.WriteLine($"Error during conversion: {ex.Message}");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment