JsonStringCaseConverter 0.1.0
See the version list below for details.
dotnet add package JsonStringCaseConverter --version 0.1.0
NuGet\Install-Package JsonStringCaseConverter -Version 0.1.0
<PackageReference Include="JsonStringCaseConverter" Version="0.1.0" />
paket add JsonStringCaseConverter --version 0.1.0
#r "nuget: JsonStringCaseConverter, 0.1.0"
// 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
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 | Versions 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. |
-
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.