JSON to ReScript Type Generator

Convert JSON data into ReScript type definitions with proper type inference, option types, and nested record support.

What is JSON to ReScript Type Generator?

This tool converts JSON data into ReScript type definitions with proper type inference. It automatically maps JSON types to ReScript types (string, int, float, bool, option, array) and handles nested objects as record types.

How to Use

  1. Select output format (record or abstract type)
  2. Paste your JSON data into the input area
  3. Set the root type name
  4. Click "Generate" and copy the ReScript types

Why Use This Tool?

Automatically infer ReScript types from JSON values
Generate record or abstract type definitions
Handle nested objects as separate type definitions
Map null values to option types for type safety
Support for arrays with element type inference

Tips & Best Practices

  • Use realistic sample data for accurate type inference
  • Record types are most common for JSON data modeling
  • Option types (option<type>) handle nullable JSON fields
  • Combine with @glennsl/rescript-json-combinators for decoding

Frequently Asked Questions

How are JSON types mapped to ReScript?

JSON strings → string, integers → int, floats → float, booleans → bool, null → option<type>, arrays → array<type>, nested objects → separate record type definitions.

What is the difference between record and abstract types?

Record types define the structure with named fields (type t = {name: string, age: int}). Abstract types define a type without exposing its structure, useful for encapsulation and module boundaries.

How are null values handled?

JSON null values are mapped to ReScript option types. For example, a nullable string field becomes option<string>, which can be Some("value") or None.

Can I use these types with JSON decoding?

Yes, the generated types work with JSON decoding libraries. Use @glennsl/rescript-json-combinators or the built-in Js.Json module to write decoders that match these type definitions.

Is my data sent to a server?

No, all processing happens entirely in your browser. Your JSON data never leaves your device.

Related Tools