JSON to F# Converter
F# record types from a JSON sample
JSON Input
F# Output
What does the JSON to F# converter generate?
F# developers usually reach for a type provider when exploring JSON, but for code you ship you often want plain, explicit types. Paste a JSON sample here and you get one F# record per object, PascalCase field names, and a [<JsonPropertyName("subscriberId")>] attribute on every field so System.Text.Json maps the original camelCase key.
Records are written in dependency order, nested types first, so they compile top to bottom without and chains. Strings become string, decimals float, booleans bool, and integers int, int64, uint64 or decimal depending on the largest value seen. Arrays become list (Device list, int list list for nested arrays). Fields that were null, or missing from some objects in an array, become option types. Values whose type varied, or that were only null, become JsonElement, so nothing is guessed.
The generator does not create discriminated unions or serializers; it gives you the record shapes. System.Text.Json in .NET 6 and later reads F# records, lists and options directly. For unions or finer control, the FSharp.SystemTextJson package is the usual choice. Everything here runs in your browser.
How to use it
Paste JSON and the records appear a moment later.
Paste a JSON sample
Paste into the JSON Input panel, Upload a .json or .txt file, or click Sample. Example input:
{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}Set Type Name for the root record. An array of objects at the root works too; the items become the root record. Check odd input with the JSON Validator first.
Read the records
The F# Output panel opens with the open lines it needs, then the records from the innermost outward. For the sample you get Account, Device, Subscriber and finally RootObject.
Copy or download
Copy to the clipboard or Download an .fs file, then deserialize with JsonSerializer.Deserialize<RootObject> json.
Where this saves time
Typed API clients
Capture a response from the service you call, generate the records, and replace JsonDocument lookups with pattern-matchable data.
Freezing a type-provider schema
Prototyped with a JSON type provider? Generate explicit records from the same sample so your build no longer depends on a sample file at compile time.
Scripts and notebooks
Paste the records into an .fsx script or a Polyglot notebook and work with typed data while exploring an export.
Finding the optional fields
Paste several real records as an array. Fields that are absent or null in any of them come out as option, which tells you where to handle None.
Common Questions
Does it generate discriminated unions?
No. JSON has no union tag to infer one from, so the output is records, lists and options only. Mixed-type values become JsonElement for you to match on.
Why do the fields have JsonPropertyName attributes?
F# field names are PascalCase while most JSON keys are camelCase, and System.Text.Json matches case-sensitively by default. The attribute keeps the original key, including keys like user-id that can't be F# names as they are.
How are big integers typed?
The page reads integers exactly, so an ICCID like 8901240544102066246 becomes int64 rather than a rounded float. Values above the uint64 range become decimal.
What about an empty object?
An empty {} says nothing about its keys, so it becomes Map<string, JsonElement>. If the whole root is empty, or null, or a bare value, the output explains why there is nothing to generate.
Is my data uploaded?
No. The records are generated by JavaScript in this page and nothing is sent to a server. Inputs over 256 KB are refused.
Other JSON Tools You Might Need
Working in C# too, or need to tidy the JSON first?