Tomlyn 0.4.1

Tomlyn Build Status NuGet

Tomlyn is a TOML parser, validator and authoring library for .NET Framework and .NET Core

Features

  • Very fast parser, GC friendly.
  • Compatible with the latest TOML 1.0.0 specs.
  • Support perfect load/save roundtrip while preserving all spaces, new line, comments.
  • Provides a validator with the Toml.Validate method.
  • Provides accurate parsing and validation error messages with precise source location.
  • Allow to work on the syntax tree directly (preserving styles) through the Toml.Parse.
  • Allow to work with a runtime representation Toml.ToModel and Toml.ToModel<T> (but cannot be saved back to TOML).
  • Supports for .NET Standard 2.0+.

Usage

var input = @"[mytable]
key = 15
val = true
";

// Gets a syntax tree of the TOML text
var doc = Toml.Parse(input); // returns a DocumentSyntax
// Check for parsing errors with doc.HasErrors and doc.Diagnostics
// doc.HasErrors => throws an exception

// Prints the exact representation of the input
var docStr = doc.ToString();
Console.WriteLine(docStr);

// Gets a runtime representation of the syntax tree
var table = doc.ToModel();
var key = (long) ((TomlTable) table["mytable"])["key"];
var value = (bool) ((TomlTable) table["mytable"])["val"];
Console.WriteLine($"key = {key}, val = {value}");

Creates a TOML document programmatically:

var doc = new DocumentSyntax()
{
    Tables =
    {
        new TableSyntax("test")
        {
            Items =
            {
                {"a", 1},
                {"b", true },
                {"c", "Check"},
                {"d", "ToEscape\nWithAnotherChar\t" },
                {"e", 12.5 },
                {"f", new int[] {1,2,3,4} },
                {"g", new string[] {"0", "1", "2"} },
                {"key with space", 2}
            }
        }
    }
};
Console.WriteLine(doc);
// Prints:
// [test]
// a = 1
// b = true
// c = "Check"
// d = "ToEscape\nWithAnotherChar\t"
// e = 12.5
// f = [1, 2, 3, 4]
// g = ["0", "1", "2"]
// "key with space" = 2

License

This software is released under the BSD-Clause 2 license.

Credits

Modified version of the logo Thor by Mike Rowe from the Noun Project (Creative Commons)

Author

Alexandre Mutel aka xoofx.

No packages depend on Tomlyn.

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
2.3.0 2 03/29/2026
2.2.1 2 03/29/2026
2.2.0 1 03/29/2026
2.1.0 1 03/29/2026
2.0.1 2 03/29/2026
2.0.0 1 03/29/2026
1.2.0 1 03/29/2026
1.1.1 1 03/29/2026
1.1.0 1 03/29/2026
1.0.0 1 03/29/2026
0.20.0 1 03/29/2026
0.19.0 1 03/29/2026
0.18.0 1 03/27/2026
0.17.0 1 03/29/2026
0.16.2 1 03/29/2026
0.16.1 1 03/29/2026
0.16.0 1 03/29/2026
0.15.1 2 03/29/2026
0.15.0 2 03/29/2026
0.14.4 1 03/29/2026
0.14.3 1 03/29/2026
0.14.2 1 03/29/2026
0.14.1 1 03/29/2026
0.14.0 1 03/29/2026
0.13.1 1 03/29/2026
0.13.0 1 03/29/2026
0.12.1 2 03/29/2026
0.12.0 1 03/29/2026
0.11.0 2 03/29/2026
0.10.2 1 03/29/2026
0.10.1 1 03/29/2026
0.10.0 1 03/29/2026
0.9.1 1 03/29/2026
0.9.0 1 03/29/2026
0.4.1 1 03/29/2026
0.4.0 2 03/29/2026
0.3.1 1 03/29/2026
0.3.0 2 03/29/2026
0.1.2 1 03/29/2026
0.1.1 1 03/29/2026
0.1.0 2 03/29/2026