JSON to C# records

Paste a JSON sample. Arrays of objects are merged, so properties missing from some items come out nullable.

Turning settings into environment variables? See appsettings.json ⇄ environment variables.

Questions

How are types chosen?

Whole numbers become int (or long past int’s range), other numbers double, true/false bool. Objects become their own record or class, named after the property; arrays become List<T>. With detection on, ISO 8601 dates become DateTime or DateTimeOffset (when they carry Z or an offset) and GUIDs become Guid. Mixed or unknown values become JsonElement.

When is a property nullable?

When the sample has null for it, or when it’s missing from some items of an array of objects.

Why JsonPropertyName?

Property names are converted to PascalCase. Where that differs from the JSON name, the attribute names the JSON property explicitly, so deserialization works without case-insensitive options.

Has the output been tested?

Yes, for the samples in this site’s tests: the generated records and classes were compiled with the C# compiler and used to deserialize each sample with System.Text.Json, and the values came back unchanged. Check the result against more of your real data, since one sample can’t show every case.

More tools

Runs in your browser: nothing you paste is sent anywhere. Not affiliated with Microsoft, the .NET Foundation or the library authors.