JSON to C# classes
Paste a JSON document, a response from an API or a line from a log. You get the C# types that deserialise it: records or classes, for System.Text.Json or Newtonsoft.Json, with properties made nullable where the sample is inconsistent. Converted in your browser; the JSON is not sent anywhere.
C#
How it decides
- Names
- Property names become PascalCase. Where that changes the name, the original is kept in a [JsonPropertyName] or [JsonProperty] attribute so round-tripping works.
- Types
- Whole numbers are int, or long if any value is too big; decimals are double; ISO 8601 strings are DateTimeOffset; GUID-shaped strings are Guid. A value that is sometimes one type and sometimes another becomes object, with a warning.
- Arrays of objects
- Every object in an array is merged into one class. A property present in some items and not others, or null in any of them, is made nullable.
- Class names
- Nested objects are named after their property; items in an array take the singular of the array name (lines becomes Line). Clashes get a number.
What to check by hand
The generator sees one sample. A property that is always present in it may be optional in reality; a number that happens to be whole may be a decimal elsewhere; an empty array says nothing about what it holds. Read the API's documentation for the fields that matter, and prefer decimal for money, which no JSON sample can tell apart from double.
With System.Text.Json, a non-nullable property that is missing from the input is left at its default rather than causing an error. If you want missing data to fail fast, use the required modifier on the properties that must be there.
Integrating with an API that keeps changing shape?
We build and maintain integrations between business systems, with the contract tests that catch the next change before your users do.