/o9d-json

Extensions for System.Text.Json

Primary LanguageC#MIT LicenseMIT

Json Icon

JSON Extensions

NuGet NuGet License

Build Coverage Status Quality Gate Status

Extensions for System.Text.Json.

Quick Start

Add the O9d.Json.Formatting package from NuGet

dotnet add package O9d.Json.Formatting

If you want to use a pre-release package, you can download them GitHub packages.

Features

Snake Case Formatting

This O9d.Json.Formatting library adds support for snake_case formatting to System.Text.Json which is still missing. The included implementation originates from the Newtonsoft.Json project.

To configure snake case formatting when using JsonSerializer directly:

var options = new JsonSerializerOptions()
{
    PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy()
};

string json = JsonSerializer.Serialize(someObj, options);

To configure snake case formatting in an ASP.NET Core MVC project:

services.AddControllers()
    .AddJsonOptions(options => 
    {
        options.JsonSerializerOptions.PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy()
    });

Or in ASP.NET 6.0 Minimal APIs:

builder.Services.Configure<JsonOptions>(options =>
{
    options.SerializerOptions.PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy());
});

Pre-release Packages

Pre-release packages can be downloaded from GitHub Packages.

dotnet add package O9d.Json.Formatting --prerelease --source https://nuget.pkg.github.com/benfoster/index.json

More information on using GitHub packages with .NET.

Building locally

This project uses Cake to build, test and publish packages.

Run build.sh (Mac/Linux) or build.ps1 (Windows) To build and test the project.

This will output NuGet packages and coverage reports in the artifacts directory.

Contributing

To contribute to O9d.Json, fork the repository and raise a PR. If your change is substantial please open an issue first to discuss your objective.

Docs

The JSON documentation is built using DocFx. To build and serve the docs locally run:

./build.sh --target ServeDocs

This will serve the docs on http://localhost:8080.