ASP .NET Core model as json
dev.to·12w·
Discuss: DEV

Introduction

When a developer needs to view the instance of a model at runtime, an easy way is to display the details as JSON. Here, learn how to do this was formatted json.

Below shows the result of colorized JSON using the NuGet package Spectre.Console.Json with formatting of JSON in the Program.cs

builder.Services.Configure<JsonOptions>(options =>
{
options.SerializerOptions.WriteIndented = true;
});

Class project SpectreConsoleJsonLibrary

Provides a method to render JSON colorized rather than placing the code in the front-end project, as this code is only needed for the development environment.

Sample

Inject using a primary constructor JsonOptions

public class ViewContac...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help