JorgeSerrano.Json.JsonSnakeCaseNamingPolicy
0.9.0
dotnet add package JorgeSerrano.Json.JsonSnakeCaseNamingPolicy --version 0.9.0
NuGet\Install-Package JorgeSerrano.Json.JsonSnakeCaseNamingPolicy -Version 0.9.0
<PackageReference Include="JorgeSerrano.Json.JsonSnakeCaseNamingPolicy" Version="0.9.0" />
paket add JorgeSerrano.Json.JsonSnakeCaseNamingPolicy --version 0.9.0
#r "nuget: JorgeSerrano.Json.JsonSnakeCaseNamingPolicy, 0.9.0"
// Install JorgeSerrano.Json.JsonSnakeCaseNamingPolicy as a Cake Addin #addin nuget:?package=JorgeSerrano.Json.JsonSnakeCaseNamingPolicy&version=0.9.0 // Install JorgeSerrano.Json.JsonSnakeCaseNamingPolicy as a Cake Tool #tool nuget:?package=JorgeSerrano.Json.JsonSnakeCaseNamingPolicy&version=0.9.0
⚠ Note
.NET 8 now has built-in support for snake_case and kebab-case JSON naming policies.
JsonNamingPolicy
Naming policies for System.Text.Json
This GitHub repo contains classes to change the name properties of a JSON into different naming conventions.
JsonSnakeCaseNamingPolicy
This class creates a policy to change the name properties of a JSON into SnakeCase (snake_case) used in some programming languages and APIs.
This code passes the tests that you will find in the corefx SnakeCaseUnitTests of Microsoft
Use
using JorgeSerrano.Json;
...
var options = new JsonSerializerOptions() { PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy() };
var person = new Person() { FirstName = "Jorge", Birthday = DateTime.UtcNow, MyJobCity = "Madrid" };
var json = JsonSerializer.Serialize(person, options);
Result
{"first_name":"Jorge","birthday":"2020-01-03T20:00:59.6991482Z","my_job_city":"Madrid"}
JsonKebabCaseNamingPolicy
This class creates a policy to change the name properties of a JSON into KebabCase (kebab-case).
Use
using JorgeSerrano.Json;
...
var options = new JsonSerializerOptions() { PropertyNamingPolicy = new JsonKebabCaseNamingPolicy() };
var person = new Person() { FirstName = "Jorge", Birthday = DateTime.UtcNow, MyJobCity = "Madrid" };
var json = JsonSerializer.Serialize(person, options);
Result
{"first-name":"Jorge","birthday":"2020-01-03T20:00:59.6991482Z","my-job-city":"Madrid"}
Disclaimer
This library is written by J0rgeSerran0 on GitHub, not by me. I packaged and published it to NuGet just for convenience.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on JorgeSerrano.Json.JsonSnakeCaseNamingPolicy:
Package | Downloads |
---|---|
Altairis.Pushover.Client
C#/.NET client for the Pushover.net service web API. |
|
Crossroad
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.9.0 | 443,172 | 4/9/2021 |