https://github.com/devlooped/spectre.yaml
Display YAML in Spectre.Console
https://github.com/devlooped/spectre.yaml
dotnet spectre-console yaml
Last synced: 2 months ago
JSON representation
Display YAML in Spectre.Console
- Host: GitHub
- URL: https://github.com/devlooped/spectre.yaml
- Owner: devlooped
- License: mit
- Created: 2026-04-09T23:14:22.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-14T00:23:17.000Z (2 months ago)
- Last Synced: 2026-04-14T15:30:03.749Z (2 months ago)
- Topics: dotnet, spectre-console, yaml
- Language: C#
- Homepage:
- Size: 222 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license.txt
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Spectre.Yaml
[](https://www.nuget.org/packages/Devlooped.Spectre.Yaml)
[](https://www.nuget.org/packages/Devlooped.Spectre.Yaml)
[](https://github.com/devlooped/oss/blob/main/osmfeula.txt)
[](https://github.com/devlooped/oss/blob/main/license.txt)
## Open Source Maintenance Fee
To ensure the long-term sustainability of this project, users of this package who generate
revenue must pay an [Open Source Maintenance Fee](https://opensourcemaintenancefee.org).
While the source code is freely available under the terms of the [License](license.txt),
this package and other aspects of the project require [adherence to the Maintenance Fee](osmfeula.txt).
To pay the Maintenance Fee, [become a Sponsor](https://github.com/sponsors/devlooped) at the proper
OSMF tier. A single fee covers all of [Devlooped packages](https://www.nuget.org/profiles/Devlooped).
## Overview
**Devlooped.Spectre.Yaml** adds a `YamlText` renderable to [Spectre.Console](https://spectreconsole.net/)
that displays YAML with syntax-highlighted tokens (keys, strings, numbers, booleans, nulls, and
comments). It also accepts JSON and arbitrary .NET objects, automatically converting them to YAML
before rendering.

## Usage
### From a YAML string
```csharp
using Spectre.Console;
AnsiConsole.Write(new YamlText("""
server:
host: localhost
port: 8080
tls: true
"""));
```
### From a .NET object
```csharp
using Spectre.Console;
var config = new
{
Server = new { Host = "localhost", Port = 8080, Tls = true },
Retries = 3,
Tags = new[] { "web", "api" },
};
AnsiConsole.Write(new YamlText(config));
```
`System.Text.Json.JsonSerializer` serializes the object; the resulting JSON is then converted
to YAML. `JsonNode` and `JsonElement` overloads are also available.
### Inside a Panel
```csharp
using Spectre.Console;
AnsiConsole.Write(
new Panel(new YamlText(myObject))
.Header("Configuration")
.BorderColor(Color.Yellow)
.Padding(1, 1));
```
## Customizing colors
Each token type has a configurable `Style`. Use the fluent extension methods for the most
concise syntax:
```csharp
var text = new YamlText(yaml)
.KeyColor(Color.Yellow)
.StringColor(Color.Cyan1)
.NumberColor(Color.Blue)
.BooleanColor(Color.Green)
.NullColor(Color.Grey)
.CommentColor(Color.DarkSlateGray1);
AnsiConsole.Write(text);
```
Or assign `Style` objects directly when you need full control (foreground, background,
decorations):
```csharp
var text = new YamlText(yaml)
{
KeyStyle = new Style(Color.Yellow, decoration: Decoration.Bold),
StringStyle = new Style(Color.Cyan1),
};
```
### Default colors
| Token | Default |
|----------|---------------------|
| Key | `Color.Grey` |
| String | `Color.Red` |
| Number | `Color.Blue` |
| Boolean | `Color.Green` |
| Null | `Color.Grey` |
| Comment | `Color.Grey` + Dim |
---
# Sponsors
[](https://github.com/clarius)
[](https://github.com/MFB-Technologies-Inc)
[](https://github.com/khamza85)
[](https://github.com/sandrock)
[](https://github.com/drivenet)
[](https://github.com/Keflon)
[](https://github.com/tbolon)
[](https://github.com/kfrancis)
[](https://github.com/rbnswartz)
[](https://github.com/jfoshee)
[](https://github.com/Mrxx99)
[](https://github.com/eajhnsn1)
[](https://github.com/Jonathan-Hickey)
[](https://github.com/KenBonny)
[](https://github.com/SimonCropp)
[](https://github.com/agileworks-eu)
[](https://github.com/arsdragonfly)
[](https://github.com/vezel-dev)
[](https://github.com/ChilliCream)
[](https://github.com/4OTC)
[](https://github.com/DominicSchell)
[](https://github.com/adalon)
[](https://github.com/torutek)
[](https://github.com/mccaffers)
[](https://github.com/SeikaLogiciel)
[](https://github.com/wizardness)
[](https://github.com/latonz)
[](https://github.com/prime167)
[](https://github.com/sponsors/devlooped)
[Learn more about GitHub Sponsors](https://github.com/sponsors)