JsonStringCaseConverter 1.0.0

.NET 6.0
dotnet add package JsonStringCaseConverter --version 1.0.0
NuGet\Install-Package JsonStringCaseConverter -Version 1.0.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="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonStringCaseConverter --version 1.0.0
#r "nuget: JsonStringCaseConverter, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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=1.0.0

// Install JsonStringCaseConverter as a Cake Tool
#tool nuget:?package=JsonStringCaseConverter&version=1.0.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();

There is also an extension of the separating string into words with case register.

var words = someText.SplitForWords();
// words = ["some", "Text", "WITH", "SaVing", "case", "REGISTER"]
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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 231 7/20/2022
0.1.0 233 7/16/2022

Improved splitting strings into words;
Added the ability to save words in the string in uppercase for camelcase and pascalcase;
Added documentation for the code.