JSON to Ecto Schema Generator

Generate Elixir Ecto schema definitions with changeset functions from JSON data.

What is JSON to Ecto Schema Generator?

This tool converts JSON data into Elixir Ecto schema definitions with changeset functions. It automatically maps JSON types to Ecto field types, generates embeds_one/has_one for nested objects, and creates changeset validation functions.

How to Use

  1. Set the module prefix for your Elixir app
  2. Configure schema options (embeds vs associations, timestamps)
  3. Paste your JSON data and click "Generate"
  4. Copy the Ecto schemas into your Phoenix project

Why Use This Tool?

Automatically infer Ecto field types from JSON values
Generate schema definitions with proper Ecto conventions
Handle nested objects with embeds_one or has_one
Include changeset functions with validate_required
Support for embedded schemas and database schemas

Tips & Best Practices

  • Use embeds_one for value objects stored in the same table
  • Use has_one for separate table associations
  • The changeset function includes validate_required for non-null fields
  • Arrays map to {:array, :type} Ecto type

Frequently Asked Questions

How are JSON types mapped to Ecto types?

JSON strings map to :string, integers to :integer, floats to :float, booleans to :boolean, null values produce fields with no required constraint, arrays of strings become {:array, :string}, arrays of objects become has_many associations, and nested objects become embeds_one or has_one depending on your selection.

What is the difference between embeds_one and has_one?

embeds_one stores the nested data in the same database table using Ecto embedded schemas, serialized as a JSONB column. has_one creates a separate table association with a foreign key reference. Use embeds_one for value objects that don't need independent querying, and has_one for entities with their own lifecycle.

What is an embedded_schema in Ecto?

An embedded_schema is an Ecto schema that is not backed by its own database table. Instead, it is stored as part of the parent record, typically in a JSONB column. Embedded schemas are useful for value objects like addresses that don't need to be queried independently.

How does the changeset function work?

The generated changeset function uses cast to filter and coerce input attributes, cast_embed or cast_assoc to handle nested data, and validate_required to enforce that non-null fields must be present. This follows the standard Ecto changeset pattern used in Phoenix applications.

Is my data sent to a server?

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

Related Tools