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
- Select output format (record or abstract type)
- Paste your JSON data into the input area
- Set the root type name
- Click "Generate" and copy the ReScript types
Why Use This Tool?
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.