JSON Input

F# Output

What Is JSON to F#?

F# uses discriminated unions and records for data. Libraries like FSharp.Data or Thoth.Json handle JSON serialization. This tool generates F# types (records, unions) from your JSON structure so you can parse API responses with type safety. The JSON specification defines the input format.

Conversion runs in your browser. Set the type name in the config panel. Nothing is sent to a server. The generated types work with .NET and F# projects. For C# interop, use JSON to C#.

How to Use This Tool

1

Paste or Upload JSON

Paste your JSON or upload a file. Set the type name in the config panel. Invalid JSON will show an error. Use the JSON Validator to check syntax first.

2

Review the F# Output

The right panel shows generated F# types. Add Thoth.Json or FSharp.Data and derive encoders/decoders as needed. Adjust optional fields to Option types for nullable JSON values.

3

Copy or Download

Use Copy or Download. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.

JSON to F# Examples

Here is an example of generating F# types from a JSON object.

Example: Subscriber record

JSON input:

Input

Generated F# output:

Output

When JSON to F# Helps

When building F# or .NET applications that consume REST APIs, you need typed models for the response payload. Pasting a sample response here gives you F# records or unions you can use with Thoth.Json or FSharp.Data. The F# language and F# documentation cover records and discriminated unions. For pulling out specific values first, use the JSON Path tool.

Frequently Asked Questions

Option for optional fields?

Use Option<T> for optional JSON fields. Thoth.Json and FSharp.Data handle null and missing keys. Without Option, missing fields will cause a decoding error.

Thoth.Json vs FSharp.Data?

Thoth.Json uses F#-style encoders/decoders. FSharp.Data provides type providers and JSON parsing. Both work with the generated types. Choose based on your project's dependencies.

Is my data private?

Yes. Generation runs entirely in your browser. No JSON or code is sent to any server.

Records vs classes?

F# records are immutable and concise. The generator typically produces records. Use classes if you need mutable state or C# interop requirements.

Can I use with Suave or Giraffe?

Yes. Giraffe is a popular F# web framework. The generated types work with HTTP handlers. Use Thoth.Json or similar for request/response serialization. For API testing, Postman and jq are useful.

Related Tools

FSharp.Data. Thoth.Json. JSON spec. MDN JSON. RFC 8259. F#. .NET.