Andeart.JsonButler
1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Andeart.JsonButler --version 1.0.3
NuGet\Install-Package Andeart.JsonButler -Version 1.0.3
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="Andeart.JsonButler" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Andeart.JsonButler --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Andeart.JsonButler, 1.0.3"
#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 Andeart.JsonButler as a Cake Addin #addin nuget:?package=Andeart.JsonButler&version=1.0.3 // Install Andeart.JsonButler as a Cake Tool #tool nuget:?package=Andeart.JsonButler&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JsonButler
JsonButler is now also available as a Visual Studio extension. Check it out here!
JsonButler lets you:
- Generate C# types (along with the cs files if needed) from JSON data. Also generates nested custom types if needed.
- Serialize a known C# type to JSON without having to instantiate an instance of said type. It drills down and uses default values as far as possible.
Code Generation
Example usage with Butler CLI (included in cli
folder):
# JsonButler can parse json text-snippets directly...
butler generate -j {"indices":[2,3,5,7]}
# ...or can instead parse the contents of a file.
butler generate -f response_payload.json
# By default, the generated C# code is copied directly to the clipboard.
# This can be overriden by setting an output file.
butler generate -f response_payload.json -o ResponseModel.cs
Example usage with C# library:
// JsonButler can parse json text-snippets directly...
string input = myJsonText;
// ...or can instead parse the contents of a file.
input = ButlerReader.ReadAllText (myJsonFilePath);
// Generates C# code (i.e. contents of potential C# file).
string generatedCsCode = ButlerCodeGenerator.GenerateCodeFile (input);
// JsonButler can either copy this text to the clipboard...
ButlerWriter.SetClipboardText (generatedCode);
// ...or write it to a file.
ButlerWriter.WriteAllText (outputFile, generatedCode);
Serialization
Example usage with C# library:
// Run JSONButler serialization with no customisation...
string serialized = ButlerSerializer.SerializeType<MyResponsePayload> ();
// ...or pass in specific serialization settings, such as limiting the scope of type generation, ...
ButlerSerializerSettings serializerSettings = new ButlerSerializerSettings (Assembly.GetExecutingAssembly ());
// ...setting constructor priorities for default object creation, ...
serializerSettings.PreferredAttributeTypesOnConstructor = new[] { typeof(MyConstructorAttribute), typeof(ClientsConstructorAttribute) };
// ... and customising the final JSON serialization.
serializerSettings.JsonSerializerSettings = myJsonSerializerSettings;
string serialized = ButlerSerializer.SerializeType<MyResponsePayload> (serializerSettings);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- Andeart.CaseConversions (>= 2.0.3)
- Costura.Fody (>= 3.1.0)
- Microsoft.CodeAnalysis.CSharp (>= 2.0.0)
- Newtonsoft.Json (>= 8.0.3)
- System.Collections.Immutable (>= 1.3.1)
- System.Reflection.Metadata (>= 1.4.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
CLI tool is now included with nuget package.