Created
December 10, 2025 11:19
-
-
Save GroupDocsGists/9a6e1ffeb7cbd9daf2779033d33972da to your computer and use it in GitHub Desktop.
Convert JSON to XML with GroupDocs.Conversion for .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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