JSON to Gleam Type Generator

Generate Gleam custom type definitions with proper type inference from JSON data.

What is JSON to Gleam Type Generator?

This tool converts JSON data into Gleam custom type definitions with proper type inference. It automatically maps JSON types to Gleam types (String, Int, Float, Bool) and handles nullable fields with Option types and nested objects as separate custom types.

How to Use

  1. Set the module name for the generated Gleam code
  2. Paste your JSON data into the input area
  3. Click "Generate" and copy the Gleam types into your project

Why Use This Tool?

Automatically infer Gleam types from JSON values
Generate custom type definitions with named fields
Handle nullable fields with Option types
Support nested objects as separate custom types
Proper Gleam syntax with pub visibility

Tips & Best Practices

  • Gleam custom types use PascalCase for type names
  • Field names use snake_case in Gleam
  • Null values become Option(T) with None default
  • Lists are typed as List(ElementType)

Frequently Asked Questions

How are JSON types mapped to Gleam?

JSON strings → String, integers → Int, floats → Float, booleans → Bool, null → Option(T) or Nil, arrays → List(T), objects → separate custom types with named fields.

What is a custom type in Gleam?

Custom types in Gleam are algebraic data types that can hold data in named fields. They are similar to structs in other languages but are defined with variant constructors. Each variant can have positional or named arguments.

How are nested objects handled?

Nested JSON objects are converted to separate Gleam custom type definitions. They are ordered children-first so that referenced types are defined before the types that use them.

What is the Option type for nullable fields?

When "Use Option for nullable fields" is enabled, JSON null values are typed as Option(T) where T is the inferred type. The gleam/option module is automatically imported. This follows Gleam convention of using Option for nullable values instead of null references.

Is my data sent to a server?

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

Related Tools