JSON to Crystal Struct Generator

Generate Crystal struct definitions with property type annotations from JSON data.

What is JSON to Crystal Struct Generator?

This tool converts JSON data into Crystal struct definitions with property type annotations. It automatically infers Crystal types from JSON values, generates property declarations, and creates properly structured structs with nested object support.

How to Use

  1. Paste your JSON data into the input area
  2. Click "Generate" to create Crystal struct definitions
  3. Copy the output and use it in your Crystal project

Why Use This Tool?

Automatically infer Crystal types from JSON values (String, Int32, Float64, Bool, Nil)
Generate Crystal struct definitions with property type annotations
Handle nested objects as separate Crystal struct definitions
Support for arrays with proper type inference
Generate children-first struct ordering for proper compilation

Tips & Best Practices

  • Use realistic sample data — type inference depends on actual values
  • Nested objects become separate structs with PascalCase names
  • Null values are typed as Nil for Crystal null safety
  • Empty arrays default to Array(String) type

Frequently Asked Questions

How are JSON types mapped to Crystal?

JSON strings → String, integers → Int32, floats → Float64, booleans → Bool, null → Nil, arrays → Array(Type), objects → separate nested struct definitions.

What is a struct in Crystal?

A struct in Crystal is a value type allocated on the stack. It has a fixed set of properties with type annotations. Structs are more efficient than classes for small, immutable data structures.

How are nested objects handled?

Nested JSON objects are converted to separate Crystal struct definitions. They are ordered children-first so that referenced structs are defined before the structs that use them.

What is the property keyword in Crystal?

property declares both a getter and setter method for a struct field. It allows you to read and modify the field value. Crystal also supports getter (read-only) and setter (write-only) declarations.

Is my data sent to a server?

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

Related Tools