Toon.DotNet.CSV 1.7.2

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

Toon.DotNet.CSV


.NET 10.0.NET 9.0.NET 8.0 .NET Nuget

NuGet NuGet Downloads

License


CSV integration for ToonDotNet — convert CSV files, strings, and streams to and from TOON format.

Features

Encoding — CSV → TOON

  • Convert a CSV string directly to a TOON tabular array
  • Convert a CSV stream — read from any readable Stream
  • Open a CSV file and return its TOON representation in one call
  • Save as .toon — read a CSV file and write the TOON result straight to a file
  • Async file supportFromCsvAsync and SaveAsToonAsync for non-blocking I/O

Decoding — TOON → CSV

  • Convert a TOON string (root array of objects) to a CSV string
  • Write to a stream — output CSV bytes to any writable Stream
  • Save as .csv — decode a TOON string and write the result straight to a file
  • Convert a .toon file directly to a .csv file in one call
  • Async file supportToCsvAsync for non-blocking I/O

Extension methods

  • string.CsvToToon() — convert a CSV string to TOON inline
  • string.ToonToCsv() — convert a TOON string to CSV inline

Type coercion

  • Integer, floating-point, and boolean values are parsed from CSV text to their native types
  • Empty fields are treated as null
  • All other values are preserved as strings
  • Type fidelity is maintained through the full CSV → TOON → CSV round-trip

Other

  • Built on CsvHelper for robust, RFC 4180-compliant CSV parsing and writing
  • All encode/decode calls accept the standard EncodeOptions and DecodeOptions from Toon.DotNet
  • Streams are left open after read and write calls
  • 69 unit tests, 100% passing, 88% code coverage

Installation

dotnet add package Toon.DotNet.CSV

Compatibility

  • .NET 10.0
  • .NET 9.0
  • .NET 8.0

How it works

CSV data is treated as tabular — the first row provides column headers and every subsequent row becomes a TOON data row. The result is a root TOON array.

CSV structure TOON output
Header row + N data rows Root array [N]{col1,col2,...}:

Decoding reverses the mapping: the TOON root value must be an array of objects. Property names become CSV column headers and each object becomes a data row.


Quick start

Convert a CSV string to TOON

using ToonFormat.Csv;

string csv = """
    id,name,role
    1,Alice,admin
    2,Bob,user
    """;

string toon = ToonCsv.FromCsv(csv);
// [2]{id,name,role}:
//   1,Alice,admin
//   2,Bob,user

Convert a CSV file to TOON

string toon = ToonCsv.FromCsvFile("users.csv");

Convert a CSV file to TOON asynchronously

string toon = await ToonCsv.FromCsvAsync("users.csv");

Convert a TOON string to CSV

string toon = "[2]{id,name,role}:\n  1,Alice,admin\n  2,Bob,user";

string csv = ToonCsv.ToCsv(toon);
// id,name,role
// 1,Alice,admin
// 2,Bob,user

Save a CSV file as a TOON file

ToonCsv.SaveAsToon("users.csv", "users.toon");

// Async version
await ToonCsv.SaveAsToonAsync("users.csv", "users.toon");

Convert a TOON file directly to a CSV file

ToonCsv.ConvertToonToCsv("users.toon", "users.csv");

Read from and write to streams

// CSV stream → TOON string
using var csvStream = File.OpenRead("users.csv");
string toon = ToonCsv.FromCsv(csvStream);

// TOON string → CSV stream
using var outputStream = File.OpenWrite("users.csv");
ToonCsv.ToCsvStream(toon, outputStream);

Use extension methods

// CSV string → TOON
string toon = "id,name\n1,Alice\n2,Bob".CsvToToon();

// TOON → CSV string
string csv = "[2]{id,name}:\n  1,Alice\n  2,Bob".ToonToCsv();

API overview

ToonCsv static class

Encoding (CSV → TOON)
Method Description
ToonCsv.FromCsv(string csv, EncodeOptions?) Converts a CSV string to a TOON tabular array
ToonCsv.FromCsv(Stream csvStream, EncodeOptions?, Encoding?) Reads CSV from a stream and returns a TOON string
ToonCsv.FromCsvFile(string csvPath, EncodeOptions?) Opens a CSV file and returns its TOON representation
ToonCsv.SaveAsToon(string csvPath, string toonPath, EncodeOptions?) Converts a CSV file and saves the result as a .toon file
ToonCsv.FromCsvAsync(string csvPath, EncodeOptions?, CancellationToken) Asynchronously opens a CSV file and returns its TOON representation
ToonCsv.SaveAsToonAsync(string csvPath, string toonPath, EncodeOptions?, CancellationToken) Asynchronously converts a CSV file and saves the result as a .toon file
Decoding (TOON → CSV)
Method Description
ToonCsv.ToCsv(string toon, DecodeOptions?) Converts a TOON string to a CSV string
ToonCsv.ToCsvStream(string toon, Stream outputStream, DecodeOptions?, Encoding?) Converts a TOON string to CSV and writes it to a stream
ToonCsv.ToCsvFile(string toon, string csvPath, DecodeOptions?) Converts a TOON string to CSV and writes it to a file
ToonCsv.ToCsvAsync(string toon, string csvPath, DecodeOptions?, CancellationToken) Asynchronously converts a TOON string to CSV and writes it to a file
ToonCsv.ConvertToonToCsv(string toonPath, string csvPath, DecodeOptions?) Converts a .toon file to a .csv file

Extension methods

// string (CSV) → TOON
string toon = csvString.CsvToToon(options);

// string (TOON) → CSV
string csv = toonString.ToonToCsv(options);

Options

Options are passed directly from ToonDotNet and work identically here.

EncodeOptions

Property Default Description
Indent 2 Spaces per indentation level
Delimiter ',' Column delimiter for tabular rows
LengthMarker null Optional prefix for array lengths (e.g. '#' produces [#3])

DecodeOptions

Property Default Description
Indent 2 Expected spaces per indentation level
Strict true Validate array lengths and row counts
var opts = new EncodeOptions { Delimiter = '|', Indent = 4 };
string toon = ToonCsv.FromCsv(csv, opts);

Type coercion

When reading CSV, field values are automatically coerced to their native types before encoding to TOON. This preserves type information that is otherwise lost in plain-text CSV.

CSV value Parsed as TOON encoding
42 long 42
3.14 double 3.14
true / false bool true / false
Alice string Alice
(empty) null null

When converting TOON back to CSV, numbers and booleans are written as their raw text representations and empty fields are written for null values.


Dependencies

  • Toon.DotNet — core TOON encoding and decoding
  • CsvHelper — RFC 4180-compliant CSV parsing and writing

License

MIT

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 is compatible.  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 is compatible.  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
1.7.2 76 3/7/2026
1.7.1 86 2/25/2026