Sharp Cast is a free web tool for developers who want a quick way to convert models between JSON, C#, and TypeScript. It is meant for the very normal "I have this model in one format and need it in another one" moment. Paste your input, pick the conversion you want, adjust a few settings if needed, and get the result in the browser.
- Convert
JSON -> C# - Convert
JSON -> TypeScript - Convert
C# -> JSON - Convert
C# -> TypeScript - Convert
TypeScript -> C# - Convert
TypeScript -> JSON
- Blazor WebAssembly app with an in-browser editor
- Easy switching between input and output formats
- C# model generation settings when you need them
- Saved editor content and settings in local storage
- Last output snapshot so you can reopen recent results
- File upload support for source input
When converting into C#, Sharp Cast supports options such as:
NamespaceRootTypeNameUseRecordsUsePrimaryConstructorPropertyAccessArrayTypeAddAttributeIsNullableIsRequiredIsDefaultInitializedUseFileScoped
src/SharpCast.Ui: the web toolsrc/SharpCast.ModelConverter: the converter logic used by the apptests/SharpCast.ModelConverter.Tests: converter test coverage
Run the web app locally with:
dotnet run --project src/SharpCast.Ui/SharpCast.Ui.csprojIf you want to use the converter logic inside another .NET project, add a project reference:
dotnet add <YourProject>.csproj reference src/SharpCast.ModelConverter/SharpCast.ModelConverter.csprojThe repo also includes the reusable converter library that powers the app:
using System.Text.Json;
using SharpCast.ModelConverter;
var options = new ConversionOptions
{
Namespace = "My.Models",
UseRecords = true,
UsePrimaryConstructor = true,
PropertyAccess = PropertyAccess.Immutable,
ArrayType = ArrayType.IReadOnlyList,
AddAttribute = true
};
var jsonToCsharp = new JsonToCSharpConverter();
jsonToCsharp.TryConvert("{ \"name\": \"Ada\", \"age\": 30 }", options, out var csharpCode);
var csharpToTs = new CSharpToTypeScriptConverter();
csharpToTs.TryConvert("public class Person { public string Name { get; set; } }", out var tsCode);
var csharpToJson = new CSharpToJsonConverter();
csharpToJson.TryConvert(csharpCode, new JsonSerializerOptions { WriteIndented = true }, out var jsonSchema);dotnet test tests/SharpCast.ModelConverter.Tests/SharpCast.ModelConverter.Tests.csproj -c Debug --no-restore