⇄ Code & API Conversion

C# to TypeScript Converter

Convert C# classes, records and enums into TypeScript interfaces or types that match what System.Text.Json actually sends.

Matches System.Text.Json Records & generics Enum options Nullable-aware

Loading C# → TypeScript…

What this page sends

  • Your input: Processed in this tab and not sent to a server.
  • Share links: Share links put a Base64 copy of your input and output in the URL itself (after #d=). Anyone with the link can read it, so don't share a link that contains secrets.
  • Editor: On desktop screens the code editor (Monaco) is downloaded from cdn.jsdelivr.net; phones get a built-in lightweight editor instead.
  • Page load: Loading the page requests HTML, scripts and images from ByteKiln, fonts from Google Fonts, and sends Google Analytics page views, tool-usage events and catalog interactions (tool/category IDs, result status and whether a click followed search — never your input, output or search terms). Privacy & sharing

How the C# to TypeScript Converter Works

When an ASP.NET Core API and a TypeScript front end share data, the TypeScript types should describe what actually arrives over the wire — not what the C# class looks like. Those differ in small, painful ways: property names are camelCased by System.Text.Json, enums are numbers unless a converter says otherwise, DateTime is a string, a long can exceed JavaScript's safe integer range, and [JsonIgnore] properties never appear at all. This converter reads C# classes, records (including positional records) and enums with the same parser ByteKiln's C# → JSON tool uses, and maps each property to the TypeScript type of its JSON form. It follows [JsonPropertyName] and [JsonIgnore], keeps generics (Result<T> stays Result<T>), turns base classes into extends clauses, maps collections to arrays and dictionaries to Record<K, V>, and handles nullable value and reference types with either T | null or optional properties. Anything it can't map — types that aren't in your paste, interfaces, methods — is listed rather than silently dropped.

Naming

camelCase follows System.Text.Json's JsonNamingPolicy.CamelCase: the leading run of capitals is lower-cased, keeping the last one when a lower-case letter follows (URLValue becomes urlValue). [JsonPropertyName] and [JsonProperty] override it.

Type mapping

Numeric types map to number, bool to boolean, string, Guid, char, TimeSpan and DateOnly/TimeOnly to string, List<T>, IEnumerable<T>, HashSet<T> and T[] to T[], Dictionary<string, T> to Record<string, T>, and object, dynamic and JsonElement to unknown. Nullable<T> and T? become T | null or an optional property.

Enums

Explicit values are kept and implicit ones count up from the previous value, as in C#. The default output depends on whether the enum has [JsonConverter(typeof(JsonStringEnumConverter))], because that decides whether JSON carries names or numbers.

What gets skipped

Fields, constructors and methods are listed as skipped. Interfaces in a base list are ignored because they don't add serialized members. Types referenced but not pasted are kept by name with a warning, so the output still compiles once you add them.

Limitations

  • It models System.Text.Json's defaults. Newtonsoft settings are honoured only through [JsonProperty] names, and custom JsonConverters, naming policies other than camelCase and polymorphism attributes are not visible to it.
  • Only the code you paste is read: referenced types that aren't pasted are kept by name with a warning, and base classes from other files are not merged.
  • long, ulong and decimal become number, which loses precision beyond 2^53 — the tool warns, but you choose the fix (string or bigint).
  • Methods, fields and constructors are skipped, since they aren't serialized.

FAQ

Short answers for the things developers usually ask before trusting a tool.

Is my C# code uploaded?

No. The code is parsed in your browser and is not sent to a ByteKiln server. If you press Share, the link itself carries a readable copy of your input, so don't share links that contain secrets.

Why are property names camelCase?

ASP.NET Core's default JSON settings (JsonSerializerDefaults.Web) use camelCase, so a C# property OrderNumber arrives in JavaScript as orderNumber. The converter follows System.Text.Json's rules, including leading acronyms (IOPort becomes ioPort). [JsonPropertyName("x")] always wins, and you can turn camelCase off if your API keeps PascalCase.

How are enums converted?

By default, enums with [JsonConverter(typeof(JsonStringEnumConverter))] become string unions ("Pending" | "Paid"), and other enums become numeric unions, because that's what System.Text.Json sends. If you register JsonStringEnumConverter globally, pick String union; you can also emit TypeScript enums.

Why does it warn about long and decimal?

They become number, and JavaScript numbers are exact only up to 2^53. A 64-bit ID or a high-precision decimal can silently lose digits in JSON.parse. Serialize those as strings if they can exceed that range.

What happens to methods, fields and constructors?

They are skipped, because only properties are serialized by default, and the tool lists what it skipped. Nested classes become separate top-level interfaces, and base classes found in the input become extends clauses.

How are DateTime and Guid mapped?

As string by default, because JSON carries them as ISO 8601 and GUID strings. You can map DateTime to Date if your client code converts it, but a plain JSON.parse will not.

Related tools

Useful follow-ups when one conversion usually turns into three more.