F# to JSON Converter

Paste F# records or unions. Get clean JSON back.

Input

Output

Paste your F# code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

An F# record or discriminated union describes your data precisely, yet the JSON you need for an HTTP test, a Giraffe endpoint or a .NET service it talks to still gets typed by hand. Paste the F# here and the backend answers with JSON for it. One record, a union with a handful of cases, or a full module are all handled.

The output follows the libraries most F# projects already use. System.Text.Json with an F# converter, Newtonsoft.Json and Thoth.Json all write record fields as JSON keys, so that is what you get. Numeric types (int, float, decimal, bigint) are written as numbers, bool as a boolean, dates as ISO 8601 text, and an option is either the inner value or null.

Discriminated unions serialize with a discriminator so the JSON round-trips cleanly. A type Status = | Paid | Refunded of Guid comes out as {"Case":"Refunded","Fields":["..."]} or a custom tagged shape when JsonUnionCase attributes are present: matching what the dotnet/fsharp team's serializers produce. Lists, arrays, and sequences become JSON arrays. Map<string, 'T> becomes a JSON object. Tuples become JSON arrays. If you prefer a deeper dive into idiomatic F# modelling, fsharpforfunandprofit.com is worth bookmarking.

How to use it

One record or an entire Domain.fs, the path to JSON is the same three steps.

1

Paste your F# (or try the sample)

Paste F# into the left editor unchanged: record types, unions, a let order = { ... } binding, the module line at the top. Load Sample gives you an Order whose Status is the union case Shipped "TRK-99821", with a string option note and a Map of metadata.

Keep module, namespace, open, and attribute declarations: the parser ignores what it does not need. The official F# language reference is a good backup.

2

Hit Convert

Click the green Convert button. Your module is posted to the backend, which follows the let binding through every record field and union case and returns JSON. A "Converting..." overlay covers both panels in the meantime.

3

Copy the JSON

The right panel fills with indented JSON. Paste it into a Giraffe or Saturn request, an xUnit fixture, a Fable test, or your API documentation.

When this actually comes in handy

Giraffe / Saturn test fixtures

You need a JSON body to POST to a Giraffe endpoint in a test. Paste the command record, get the payload, drop it into the spec.

Fable front-end mocks

Turn your F# domain records into mock JSON responses for a Fable or Elmish front end, no more hand-rolled JS objects that drift from the types.

Azure Functions payloads

Generate the JSON body you need to call an Azure Function written in F#: works well when you are iterating on input shape.

Docs that match your types

Produce JSON samples for API documentation or a README straight from your actual records, so the docs never fall behind.

Common questions

How are Option types serialized?

Some x becomes the value x; None becomes JSON null. That matches the default behaviour of Thoth.Json and the F# converter in System.Text.Json.

What do discriminated unions look like in JSON?

By default: {"Case":"CaseName","Fields":[...]}, the tagged format that round-trips back to F#. If the code uses custom attributes (JsonUnionCase or similar), the converter respects them and emits the tailored shape instead.

How does it handle DateTime, DateTimeOffset, Guid?

Both date types turn into ISO 8601 text like "2026-04-18T14:30:00Z", and a Guid is written in its usual dashed hex form as a string, which is what System.Text.Json does without extra converters.

Lists, arrays, maps: how do they map?

list, array, and seq all become JSON arrays. Map<string, 'T> becomes a JSON object. Tuples become JSON arrays of mixed types, same as the .NET serializers produce.

Can I paste a whole module?

Yes. Every top-level record and union becomes its own JSON entry, with nested records expanded. let-bindings that construct sample values are picked up too: useful when you have a test-data module.

Is my code stored?

Your F# is posted to the backend only for this conversion and nothing is kept. Test-data modules sometimes pull real records from production, so swap those for invented ones first.

Other tools you may need

For the trip back from a JSON payload to F# or C# types, or a closer look at the output, try these: