Json2Sharp (1.1.11)
Published 2024-07-03 06:01:39 -07:00 by toastie_t0ast
Installation
dotnet nuget add source --name toastie_t0ast --username your_username --password your_token
dotnet add package --source toastie_t0ast --version 1.1.11 Json2Sharp
About this package
Parse JSON data into language type declarations.
Json2Sharp
Json2Sharp is a library that converts a JSON object to a programming language type definition (i.e. a class).
To perform a conversion, call the Parse
method from the Json2Sharp
class.
string code = Json2Sharp.Parse("Person", """{ "id": 1, "name": "John" }""");
/*
* using System.Text.Json.Serialization;
*
* public sealed record Person(
* [property: JsonPropertyName("id")] int Id,
* [property: JsonPropertyName("name")] bool Name
* );
*/
You can also customize the conversion by initializing a Json2SharpOptions
object and populating its members to suit your needs.
Json2SharpOptions options = new()
{
TargetLanguage = Language.CSharp,
CSharpOptions = new()
{
IsSealed = false,
IsPropertyRequired = false,
TargetType = CSharpObjectType.Class,
SerializationAttribute = CSharpSerializationAttribute.NewtonsoftJson
}
};
string code = Json2Sharp.Parse(className, rawJson, options);
/*
* using Newtonsoft.Json;
*
* public sealed class Person
* {
* [JsonProperty("id")]
* public int Id { get; init; }
*
* [JsonProperty("name")]
* public string Name { get; init; }
* }
*/
Details
Assets (4)
Versions (1)
View all
json2sharp.1.1.11.nupkg
27 KiB
json2sharp.nuspec
944 B
json2sharp.1.1.11.snupkg
15 KiB
json2sharp.pdb
22 KiB
1.1.11
2024-07-03