TLio.FormatConverter 0.9.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package TLio.FormatConverter --version 0.9.0
                    
NuGet\Install-Package TLio.FormatConverter -Version 0.9.0
                    
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="TLio.FormatConverter" Version="0.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TLio.FormatConverter" Version="0.9.0" />
                    
Directory.Packages.props
<PackageReference Include="TLio.FormatConverter" />
                    
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 TLio.FormatConverter --version 0.9.0
                    
#r "nuget: TLio.FormatConverter, 0.9.0"
                    
#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 TLio.FormatConverter@0.9.0
                    
#: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=TLio.FormatConverter&version=0.9.0
                    
Install as a Cake Addin
#tool nuget:?package=TLio.FormatConverter&version=0.9.0
                    
Install as a Cake Tool

TLio.FormatConverter

The convert and convertValue commands for TLio, plus MultiFormatScriptRunner — the piece that lets one script change the document's format partway through — and the JSON, XML and YAML converters they work through. One assembly, one package.

dotnet add package TLio.FormatConverter

Two commands, and what changes format

  • convert changes the whole document. That means a different TNode, which no ICommand<TNode> can return — so the engine cannot run it. MultiFormatScriptRunner splits the script at each boundary and re-hosts each section on the engine for that format. Run on a bare engine it converts nothing and says so.
  • convertValue changes one value at a path. The document's format never changes, so it is an ordinary command on the ordinary engine — the embedded-payload case, an XML string inside a JSON envelope.

Paths after a convert speak the new format's path language. That is inherent: the paths address the document, and the document has changed format.

Quick start

using TLio.FormatConverter;         // the commands and the runner
using TLio.FormatConverter.Core;    // the converter itself
using TLio.FormatConverter.Json;    // the three adapters
using TLio.FormatConverter.Xml;
using TLio.FormatConverter.Yaml;

// Fully qualified: the type's name repeats a namespace segment, so a bare
// `new FormatConverter()` is only unambiguous where `using TLio;` is absent.
var converter = new TLio.FormatConverter.Core.FormatConverter();
converter.Register(new JsonFormatAdapter());
converter.Register(new XmlFormatAdapter());
converter.Register(new YamlFormatAdapter());

var runner = new MultiFormatScriptRunner(converter);
runner.RegisterExecutor(new ScriptEngineSectionExecutor<JToken>(
    "json", jsonEngine, JsonExecutionContext.CreateDefault));
runner.RegisterExecutor(new ScriptEngineSectionExecutor<XElement>(
    "xml", xmlEngine, XmlExecutionContext.CreateWithNativeXPath));
runner.RegisterExecutor(new ScriptEngineSectionExecutor<YamlNode>(
    "yaml", yamlEngine, YamlExecutionContext.CreateDefault));

var result = runner.Run("json", document, script);
// result.Document, result.FormatId, result.Success, result.Logs

The script:

[
  { "command": "add",     "path": "$.order.status", "value": "new"    },
  { "command": "convert", "to": "yaml" },
  { "command": "add",     "path": "order.source",   "value": "portal" },
  { "command": "convert", "to": "xml"  },
  { "command": "rename",  "path": "/order",         "name":  "opdracht" }
]

MultiFormatScriptRunner.CrossesAFormatBoundary(script) is how a host decides whether a script needs the runner or a plain ScriptEngine.

Registering the commands on an engine

convertValue works on any engine; convert still needs the runner, but registering it means a script that uses it inline gets an explanation rather than "unknown command".

var options = ParseOptions<JToken>.CreateDefault();
options.CommandsProvider.RegisterFormatConversion<JToken>(converter, "json");

Settings

Per-boundary, and they do not carry to the next convert: attributePrefix, textProperty, namespacePrefix, arrayItemName, arrayHandling, nullRepresentation, nameSanitization, inferTypes, cdataAsText, flattenAnchors. Each exists where the formats genuinely disagree.

Conversion output is the canonical document shape TLio's own adapters address, so the commands after a boundary land where the paths say they do.

License

MIT — see the repository.

Product Compatible and additional computed target framework versions.
.NET 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
0.10.0-preview.1 50 8/24/2026
0.9.0 93 8/23/2026
0.9.0-preview.14 69 8/22/2026
0.9.0-preview.13 53 8/22/2026
0.9.0-preview.12 49 8/22/2026
0.9.0-preview.11 54 8/22/2026