ListToXmlOrJson 1.0.1

dotnet add package ListToXmlOrJson --version 1.0.1
                    
NuGet\Install-Package ListToXmlOrJson -Version 1.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="ListToXmlOrJson" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ListToXmlOrJson" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ListToXmlOrJson" />
                    
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 ListToXmlOrJson --version 1.0.1
                    
#r "nuget: ListToXmlOrJson, 1.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 ListToXmlOrJson@1.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=ListToXmlOrJson&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ListToXmlOrJson&version=1.0.1
                    
Install as a Cake Tool

ListToXmlOrJson ✨

A Simple & Elegant .NET Data Export Utility

.NET Version
NuGet Version
No Dependencies

Effortlessly export any List<T> to JSON or XML files with just one line of code! Built with native .NET libraries – no external dependencies.


🚀 Features

✔ One-method solution – Simple and intuitive API
✔ Supports any object type – Fully generic implementation
✔ Native .NET serialization – Uses System.Text.Json and System.Xml.Serialization
✔ Lightweight – Zero external dependencies
✔ Robust error handling – Validates inputs and throws meaningful exceptions


📦 Installation

Via NuGet Package Manager:

Install-Package ListToXmlOrJson

Or using .NET CLI:

dotnet add package ListToXmlOrJson

🛠 Usage

1️⃣ Define your model

//Example code:
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

2️⃣ Prepare your data

//Example code:
var people = new List<Person>
{
    new Person { Name = "John", Age = 30 },
    new Person { Name = "Mary", Age = 25 }
};

3️⃣ Export to JSON or XML

//Example code:
using ListToXmlOrJson;

// Export to JSON
ExportData<Person>.SaveData("people", people, ExportData<Person>.FileFormat.Json);

// Export to XML
ExportData<Person>.SaveData("people", people, ExportData<Person>.FileFormat.Xml);

This generates:

📄 people.json

📄 people.xml


📜 API Reference

ExportData<T>.SaveData

public static void SaveData(string file, List<T> data, FileFormat fileFormat)
Parameter Type Description
file string Output filename (without extension)
data List<T> Collection of objects to export
fileFormat FileFormat Export format (Json or Xml)

Exceptions:

  • ⚠️ ArgumentNullException → If data is null
  • ⚠️ Exception → If an unsupported format is provided

❓ Why Use This?

✔ No complex setup – Works out of the box
✔ Clean and maintainable – Single responsibility principle
✔ Production-ready – Proper error handling
✔ Lightweight – No bloat, just pure functionality


🌟 Example Output

JSON (people.json)

[
  {
    "Name": "John",
    "Age": 30
  },
  {
    "Name": "Mary",
    "Age": 25
  }
]

XML (people.xml)

<ArrayOfPerson>
  <Person>
    <Name>John</Name>
    <Age>30</Age>
  </Person>
  <Person>
    <Name>Mary</Name>
    <Age>25</Age>
  </Person>
</ArrayOfPerson>

🌐 Developed by NandoDeveloper

GitHub LinkedIn

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.
  • net6.0

    • No dependencies.

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
1.0.1 167 5/31/2025