json2types

Paste JSON, get C# and TypeScript types.

Everything runs in your browser: nothing you paste is uploaded.

Language
C# options
Declare
Collections

C# code

What it does

json2types reads a JSON sample, works out the types it implies and writes them as C# classes or records, or as TypeScript interfaces or types. The code updates as you type, and every option shows its effect at once.

It looks at every value, not just the first: the objects of an array are merged into one type, a property missing from some of them becomes optional, one that is null in some becomes nullable, and integers mixed with fractions become decimals. In C#, dates, date-times and GUIDs get their own types when every value in a place is one.

Questions

Is my JSON sent anywhere?

No. Parsing and conversion happen in your browser, in a background worker, and the page's security policy blocks every network request from its scripts, so nothing you paste can leave the page. The options you pick are remembered in this browser; the JSON only if you tick "Remember my JSON".

How large a JSON can it take?

Megabytes. A 1 MB sample converts in about half a second on a laptop, and the page stays responsive meanwhile, since the work runs off its main thread.

What if my JSON has an error?

The error is shown with its line and column, and "Show in the JSON" selects the spot. The last good code stays on screen, marked out of date, until the JSON is valid again.