JsonStringCaseConverter 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonStringCaseConverter --version 0.1.0                
NuGet\Install-Package JsonStringCaseConverter -Version 0.1.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="JsonStringCaseConverter" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonStringCaseConverter --version 0.1.0                
#r "nuget: JsonStringCaseConverter, 0.1.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.
// Install JsonStringCaseConverter as a Cake Addin
#addin nuget:?package=JsonStringCaseConverter&version=0.1.0

// Install JsonStringCaseConverter as a Cake Tool
#tool nuget:?package=JsonStringCaseConverter&version=0.1.0                

JsonStringCaseConverter

GitHub license NuGet Badge

Info

JsonStringCaseConverter is the string case formatting extensions for System.Text.Json.

This library helps to convert strings to the following formats:

  • Camel case;
  • Pascal case;
  • Snake case;
  • Cebab case (comming soon).

Installation

Either checkout this Github repository or install JsonStringCaseConverter via NuGet Package Manager.

If you want to use NuGet just search for JsonStringCaseConverter or run the following command in the NuGet Package Manager console:

PM> Install-Package JsonStringCaseConverter

Usage

In a part of System.Text.Json

To work with the object, use the inherited class JsonStringCaseNamingPolicy. The JsonStringCaseNamingPolicy class receives one of the formats you need in the constructor stored in the StringCases enam. The following formats are currently available:

public enum StringCases
{
    CamelCase,
    SnakeCase,
    PascalCase
}

To configure for JsonSerializer directly:

var options = new JsonSerializerOptions()
{
    PropertyNamingPolicy = new JsonStringCaseNamingPolicy(StringCases.CamelCase)
};

var json = JsonSerializer.Serialize(obj, options);

To configure for .NET Core project:

services.AddControllers()
    .AddJsonOptions(options => 
    {
        options.JsonSerializerOptions.PropertyNamingPolicy = new JsonStringCaseNamingPolicy(StringCases.PascalCase)
    });

To configure for .NET 6.0 Minimal API:

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

In a native work with strings

The library has direct extension methods that can be used with non-json strings if you need them.

var camelText = someText.ToCamelCase();

var snakeText = someText.ToSnakeCase();

var pascalText = someText.ToPascalCase();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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
1.0.0 520 7/20/2022
0.1.0 421 7/16/2022