Skip to footer content
Iron Academy Logo
C# Application
C# Application

Other Categories

Formatting JSON Output - Spectre Console Series

Tim Corey
7m 01s

Spectre Console is a .NET library that lets you build rich, colorful console applications. Instead of plain text output, you can use Spectre’s panels, tables, and even JSON formatting to present data beautifully.

In this article, we’ll take a detailed look at Spectre Console JSON as shown in Tim Corey’s video “Formatting JSON Output – Spectre Console Series.” We’ll walk through his code, his NuGet package installs, and his styling tips. You’ll see how to give your console apps “JSON superpowers” with clear syntax highlighting and easy-to-read layouts. All time markers in the headings correspond to Tim’s video so you can follow along.

Getting Started: What Spectre Console JSON Is

At 0:00, Tim introduces Spectre Console as a .NET library for creating visually appealing console applications. He explains that in this lesson he’s going to fetch JSON data from an API and display it using Spectre Console JSON. This means your string of raw JSON can be converted into a rich object that Spectre can render.

He mentions that the source code and project website link are in the description so you can download the project yourself.

Fetching JSON Data with a Helper Function

At 0:35, Tim shows the helper code. In his project, he has a Helpers class with a function called FetchApiDataAsync. This function sends a request to a URL, gets back the JSON, and returns the response as a string.

He notes you could simply use AnsiConsole.WriteLine(jsonResponse) to write the JSON to the console. But as he demonstrates at 1:26, that raw output is just a dense collection of text—not friendly for people reading or working with it.

Installing the Spectre Console JSON Package

At 1:46, Tim says he wants to format the JSON properly. But first, he needs the JSON extension package. He right-clicks the project, chooses “Manage NuGet Packages,” and installs Spectre.Console.Json.

He points out that you can also use the CLI and run:

dotnet add package Spectre.Console.Json
dotnet add package Spectre.Console.Json

This is the official NuGet package for JSON rendering. As Tim explains at 2:14, you can make an AOT (ahead-of-time) compiled app with both package Spectre and package Spectre.Console.Json, but not with the CLI at the moment.

Creating a JsonText Instance

At 2:31, Tim shows the syntax for turning your JSON string into a Spectre renderable object. He writes:

using Spectre.Console.Json;

var json = new JsonText(jsonResponse);
using Spectre.Console.Json;

var json = new JsonText(jsonResponse);

This creates a new instance of JsonText from your string. Now you have an object that Spectre can render with style. You don’t have to parse arrays, null values, or nested objects yourself—the library does it for you.

Rendering JSON Inside a Panel

At 3:00, Tim demonstrates actually writing the JSON to the console. He uses Spectre’s panel feature to frame the data:

AnsiConsole.Write(
    new Panel(json)
);
AnsiConsole.Write(
    new Panel(json)
);

At 3:39, when he runs the code, the JSON appears in a styled box. Keys are blue, numbers and booleans are green, and text values are red. Even array data and nested objects show correctly. Spectre wraps long lines automatically, so you don’t have to build the indentation or spacing yourself.

Spectre Console Formatting Json Output 1 related to Rendering JSON Inside a Panel

He also notes at 3:59 that URLs inside your JSON become clickable links in many terminals—another bonus for people reading JSON directly from a console.

Adding Headers, Borders, and Styles

At 4:09, Tim moves on to styling. He chains methods on the panel to set a header, collapse excess space, and change the border color:

var panel = new Panel(json)
    .Header("API Response")
    .Collapse()
    .BorderColor(Color.White);

AnsiConsole.Write(panel);
var panel = new Panel(json)
    .Header("API Response")
    .Collapse()
    .BorderColor(Color.White);

AnsiConsole.Write(panel);

At 5:02, when he runs this build, the console shows a polished box labeled “API Response,” exactly as you might see in a web tool or IDE. This makes information from your API much easier to read.

Spectre Console Formatting Json Output 2 related to Adding Headers, Borders, and Styles

Customizing JSON Colors

At 5:14, Tim shows you can change the color of JSON parts individually. He doesn’t change every property, just enough to demonstrate the syntax:

json.StringColor = Color.Yellow;
json.ColonColor = Color.Orange;
json.StringColor = Color.Yellow;
json.ColonColor = Color.Orange;

At 5:52, when he runs it, the text values are yellow, and the colons are orange. You can use Color.Red, Color.Green, or any other defined Spectre color. This lets you match your corporate style or highlight specific values in your console.

Why Spectre Console JSON Matters

At 6:04, Tim sums up the benefits. With Spectre Console JSON, you can:

  • Install a single NuGet package and get JSON formatting “superpowers.”

  • Take a plain string of JSON and render it as a colored object automatically.

  • Work with arrays, nested collections, null values, and large datasets without writing your own formatting code.

  • Add headers, borders, and custom colors to panels easily.

  • Keep your console applications professional and easy to read.

He stresses you don’t have to build indentation, handle spacing, or define colors manually. The library handles these operations for you.

Conclusion

At 6:38, Tim wraps up by thanking viewers. He’s shown how to fetch JSON from an API, convert it into a JsonText object, and display it inside a styled panel with custom color settings.

With just one extra NuGet package and a few lines of code, your console app can gain “JSON superpowers”—beautiful, readable output for your data.

If you want to dive deeper, check out the Spectre Console project website or Tim’s channel for more detailed instructions. As Tim demonstrates in his video, once you’ve installed the package and created your JsonText instance, all the heavy lifting is done. Your console app becomes a far more useful tool for reading, working, and sharing JSON information.

Hero Worlddot related to Formatting JSON Output - Spectre Console Series
Hero Affiliate related to Formatting JSON Output - Spectre Console Series

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!