SlickDevTools.AspNetCore.Converters.JsonToXml 3.0.1

dotnet add package SlickDevTools.AspNetCore.Converters.JsonToXml --version 3.0.1
                    
NuGet\Install-Package SlickDevTools.AspNetCore.Converters.JsonToXml -Version 3.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SlickDevTools.AspNetCore.Converters.JsonToXml" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SlickDevTools.AspNetCore.Converters.JsonToXml" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SlickDevTools.AspNetCore.Converters.JsonToXml" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SlickDevTools.AspNetCore.Converters.JsonToXml --version 3.0.1
                    
#r "nuget: SlickDevTools.AspNetCore.Converters.JsonToXml, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SlickDevTools.AspNetCore.Converters.JsonToXml@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SlickDevTools.AspNetCore.Converters.JsonToXml&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=SlickDevTools.AspNetCore.Converters.JsonToXml&version=3.0.1
                    
Install as a Cake Tool

SlickDevTools.AspNetCore.Converters.JsonToXml

A high-performance library for converting JSON data to XML format in C#. Version 3.0 includes critical bug fixes and performance improvements.

What's New in Version 3.0

  • Fixed: Primitive array handling - now correctly converts arrays like [1, 2, 3] and ["a", "b", "c"]
  • Improved: Array support for mixed content (objects and primitives)
  • Enhanced: XML documentation for better IntelliSense support

Features

  • Easy-to-use JSON to XML conversion
  • Supports primitive arrays, object arrays, and mixed arrays
  • Customization through JsonToXmlConverterOptions
  • Handles nested objects and complex JSON structures
  • Returns conversion result in JsonToXmlConverterResult object

Usage

Basic instantiation and conversion

  1. Instantiate JsonToXmlConverterService class:
JsonToXmlConverterService converterService = new JsonToXmlConverterService();
  1. Convert JSON to XML:
string json = "{ \"key\": \"value\" }";
JsonToXmlConverterResult result = converterService.Convert(json);
  1. Access the converted XML string:
string xml = result.Xml;

Alternate instantiation and conversion with options

  1. Instantiate JsonToXmlConverterService class with options:
// json string for a product
string json = @"{
    ""id"": 1,
    ""name"": ""Product 1"",
    ""price"": 100
}";
        
// create an instance of the json to xml serializer with options that sets the root element name to "product"
var service = new JsonToXmlConverterService(new JsonToXmlConverterOptions { RootElementName = "product" });
  1. Convert JSON to XML:
var result = service.Convert(json);
  1. Access the converted XML string:
// output the xml
var xmlString = result.Xml;

Classes

JsonToXmlConverterService

The main class that handles JSON to XML conversion. The constructor takes an optional JsonToXmlConverterOptions parameter to customize the conversion process. It has one public method, Convert, which takes a JSON string as input and returns a JsonToXmlConverterResult object containing the XML string.

JsonToXmlConverterOptions

A class that allows customization of the JSON to XML conversion process. Available options:

  • RootElementName: Specify the name of the root XML element (default: "root")

JsonToXmlConverterResult

A class that holds the result of the JSON to XML conversion. It has one property, Xml, which contains the converted XML string.

Dependencies

  • This library relies on the JsonToXmlConverter class to perform the actual JSON to XML conversion. Ensure that this class is included in your project.

Installation

dotnet add package SlickDevTools.AspNetCore.Converters.JsonToXml --version 3.0.0

Or via Package Manager Console:

Install-Package SlickDevTools.AspNetCore.Converters.JsonToXml -Version 3.0.0

Array Handling

Version 3.0 correctly handles all array types:

Primitive Arrays:

{ "numbers": [1, 2, 3] }

Converts to:

<root>
  <numbers>
    <item>1</item>
    <item>2</item>
    <item>3</item>
  </numbers>
</root>

Object Arrays (as before):

{ "items": [{"id": 1}, {"id": 2}] }

Mixed Arrays:

{ "mixed": [1, {"id": 2}, "text"] }

Supports: .NET 8.0

License

This project is released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 216 10/21/2025
1.1.8 196 11/14/2024
1.1.7 275 4/20/2024