How to Convert a JSON String to XML in C# .NET Core Framework
Data format conversions help ensure applications or APIs consume content correctly. When we need data in XML format instead of a JSON string, we can make our conversion without writing any code at all.
Conveniently, using the ready-to-run code examples below, we can quickly & easily convert JSON strings to XML strings using a free API.
We’ll just need a free API key to authorize our requests, and we’ll be able to make up to 800 conversions per month with no additional commitments.
We can start by installing the .NET Core SDK. Let’s run this command in our Package Manager console to install via NuGet:
Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.2.1
Now we can copy the below code into our file to call the function. Let’s copy our API key into the authorization snippet, and then let’s replace jsonString_example with our own input:
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertDataJsonStringToXmlExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertDataApi();
var jsonString = jsonString_example; // string | Input JSON String to convert to XML
try
{
// Convert JSON String to XML conversion
Object result = apiInstance.ConvertDataJsonStringToXml(jsonString);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDataApi.ConvertDataJsonStringToXml: " + e.Message );
}
}
}
}
Now we can make quick & easy conversions from JSON to XML. No more code required!