What is JSON to OCaml Type Generator?
This tool converts JSON data into OCaml type definitions. It automatically infers OCaml types from JSON values, generates properly formatted record types, and handles nested objects and arrays with full type safety.
How to Use
- Paste your JSON data into the input area
- Click "Generate" to create OCaml type definitions
- Copy the output and use it in your OCaml project
Why Use This Tool?
Tips & Best Practices
- Use realistic sample data — type inference depends on actual values
- Nested objects become separate type definitions with PascalCase names
- Field names are automatically converted to snake_case
- Null values are typed as 'a option for flexibility
- Empty arrays are typed as 'a list
Frequently Asked Questions
How are JSON types mapped to OCaml?
JSON strings → string, integers → int, floats → float, booleans → bool, null → 'a option, arrays → type list, objects → record types with { field : type; } syntax.
How are nested objects handled?
Nested JSON objects are converted to separate OCaml type definitions. They are ordered children-first so that referenced types are defined before the types that use them.
What about field naming conventions?
Field names are automatically converted to snake_case following OCaml conventions. For example, "isActive" becomes "is_active", "userName" becomes "user_name".
How are null values handled?
Null values are typed as 'a option, which is a polymorphic option type in OCaml. This provides flexibility while maintaining type safety.
Is my data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device.